Search Google

Tuesday, 9 June 2015

django tutorial for beginners create your first app startproject myproject
creates a project and files like
  • use files as an global modules
  • to manage project like, Syncdb, migrate, startserver
  • Contains The Project Settings
  • Contains Project URL,you can include the app url file
python startapp appname
creates a app inside my project and files like
  • use files as an global modules
  • You can write your model classes here
  • To write test cases
  • App URLs

1 startproject myproject
creates a project and files like,,,
2 python startapp appname
creates a app inside my project and files like,,,

Getting Django setup on Windows

A friend asked me how to setup an Django enviroment on Windows without the Cygwin fuzz. Here is the shortest steps I can think of:

1. Install Python3.4 as default path. (It should be "C:\Python34").
2. Open cmd.exe program on Windows and run the following commands:

    set PATH=%PATH%;C:\Python34;C:\Python34\Scripts
    pip install django
    python C:\Python34\Lib\site-packages\django\bin\ startproject mysite
    cd mysite
    python syncdb

    (Follow prompts to setup an initial db. remember the user you used here.)

    python runserver

3. You are ready to django! Open your browser to verify.
    Or login into with the user you setup above.
What's next?
    Explore django with a guided tutorial here:


Django Basics - Installing Django and Setting Up a Project and App

This brief tutorial shows the basics of installing and setting up a simple app in Django that is used to submit and retrieve information about books you've read:
  • Part 1 - Installing and Setting up Django
  • Part 2 - Creating the Database Model
  • Part 3 - Django API vs Admin site
  • Part 4 - Django Templates and Views
Each part includes an accompanying video. You can download the source via Github - which includes all four parts. I will be delivering this tutorial from a Windows-perspective, but the Mac OS X perspective is pretty much the same.
This tutorial follows the first few sections of the official Django tutorial.
Videos - Part 1, Part 2, Part 3, Part 4
GitHub -
Developed in 1995 Django is one of, if not the most, popular Python web frameworks. It promotes rapid development via the model-view-controller architecture. You can learn more about it here.
  • You have Python 2.7 installed.
  • You have PIP installed. To install, you need to first install setup tools. Click here for a brief tutorial on how to do that. Then you can just run the command easy_install pip from the command prompt to install PIP.

Alright let's get started …

Part 1 - Installing Django

Open the command prompt with admin privileges and run the command-

pip install Django
-to install Django into your site-packages directory.

To setup, you need to create a new project. Within command prompt, navigate to the directory you wish to create the new project, then run the command -

python C:\Python27\Lib\site-packages\django\bin\ startproject testproject
Your path to ** may be different, so make sure to tailor it if necessary. Also, *testproject* is the name of the created project. Feel free to name this whatever you like. ### Next you need to make sure everything was setup correctly. To do that, you can launch the Django server. First, navigate to your newly created directory (*testproject*, in my case), and then run the command-
python runserver
Open up a new browser window and navigate to http://localhost:8000/. If setup correctly, you will see the Welcome to Django screen. ### Let’s setup the database. Open up ** in the *testproject* directory with a text editor. (I use Notepad++.) Append *sqlite3* to the end of the Engine key and then add the path to the name key. You can name the database whatever you’d like because if the database doesn’t exist, Django will create it for you in the next step. The results should look like something similar to this (depending upon your path)-
'ENGINE': 'django.db.backends.sqlite3',    
'NAME': 'C:/Python27/django/testproject/test.db',
(Yes, use forward slashes.)

Finally, you need to create and then sync the database by navigating to the directory where is located (should be the project's main directory) and then running the following command-

python syncdb
Create a superuser. I used admin for both my username and password.
Alright, the setup is complete. You're now ready to start creating an app.

Part 2 - Creating the Database Model

Start by creating an app. Within command prompt, navigate to the testproject directory and then type the command-

python startapp books
CD into the directory. You should see a file. This file is used to setup the entities and attributes for your database.

Go ahead and open in Notepad++ and add in the following code:

class Books(models.Model):
  title = models.CharField(max_length=150)
  author = models.CharField(max_length=100)
  read = models.CharField(max_length=3)
This code should be relatively clear. This class defines the database fields- title, author, and read. The data in the read field will either be "yes" or "no" depending on whether you've read the book or not.
Since there is only one table, we don't need to establish a foreign key. The primary key, a unique id, will be automatically generated for us by Django's magic.
Save the file.

Now open up the file, scroll down to Installed Apps and add the app name, books, to the installed apps so that Django knows to include it. Your installed apps section should look like this-

    # Uncomment the next line to enable the admin:
    # 'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
Save the file.

CD back to the main project directory and run the command-

python sql books
-to display the actual SQL statements for creating the table. Did you notice the primary key?
Your output should look like this-

CREATE TABLE "books_books" (
    "id" integer NOT NULL PRIMARY KEY,
    "title" varchar(150) NOT NULL,
    "author" varchar(100) NOT NULL,
    "read" varchar(3) NOT NULL
You can also use the following command to check to see if there are any errors in your models-

python validate

Finally, you need to run the following command to execute the SQL statements:

python syncdb
Next, I'll show you how to access the Django API to add data to the database.

Part 3 - Django API vs Admin site

First open up command prompt, navigate to your project directory, and then run the command-

python shell
This opens an interactive environment for us to use.

Next go ahead and import your app with the following command-

from books.models import Books

There's a number of different things you can do within this environment, but let's stick with adding data to our database. To add a row, run this command-

b = Books(title="To Kill a Mockingbird", author="Harper Lee", read="yes")
b = Books(title="Brave New World", author="Aldous Huxley", read="yes")
b = Books(title="War and Peace", author="Leo Tolstoy", read="no")
Go ahead and add as many books as you'd like for practice.
Once complete, you can view the data in your database in a number of ways. I like to just use SQLite, which can be downloaded here. So, go ahead and open the text.db file which is located within your project's main directory, switch to the Browse Data tab, and then under the Table dropdown choose books_books. You should see all the books you added.
You can exit the Django interactive environment using the exit() command.
Okay, let's look at an even easier means of adding data using Django's admin site.

Open the file, scroll down to Installed Apps and uncomment the line 'django.contrib.admin',. Then save the file.

Update the database by running the command-

python syncdb

Next open the file within the books directory. You need to uncomment these three lines-

from django.contrib import admin
url(r'^admin/', include(,
Save the file and exit.

Now create a new file in your books directory called and add the following code to the file-

from books.models import Books
from django.contrib import admin

Next, open up your file and add these two lines of code-

def __unicode__(self):
  return self.title + " / " + + " / " +
Essentially, self refers to the current object.

Now start the development server - python runserver, point your browser to http://localhost:8000/admin, and enter your login credentials. You should see the Books app. And if you click the app, you should now see the data we added earlier.

Go ahead and add a few more books in. Try deleting a row as well. See how much easier that is in the Admin console?
So we're done with the Admin console. Hit CTRL+BREAK to exit. I'm also done showing you how to create and modify your app's model(s). Next, we'll look at how to modify what the user sees (views and templates).

Part 4 - Django Templates and Views

Again, in this final tutorial I'll go over how to create the public interface.

The first thing we need to do is setup the URL structure. Open up and then add this code to the urlpatterns-

url(r'^books/$', 'books.views.index'),
This is essentially a tuple that points a user to a Django page based on the URL that user visits. In this case the regular expression dictates that when the user visits any page with the ending /books they will be see the books.views.index page. This is a bit complicated, so be sure to visit the Django tutorial for more into.

Now to ensure that this is setup correctly run the server and then point your browser to http://localhost:8000/books.

As long as you get the error, ViewDoesNotExist at /books, then the url is setup correctly.
We need to actually write the view now.

Stop the server (CRTL+BREAK) and then within the books directory open in Notepad++ and write the following code to test out your views-

from django.http import HttpResponse
def index(request):
  return HttpResponse("Hello. This is a test.")
Save the file. Run the server. And refresh the page. You should no longer see an error. Instead, you should just see a page with the words Hello. This is a test. in the top corner.

Okay, now let's display something a bit more meaningful - like a listing of all the books in the database. To do that, you need your file to look like this-

from django.http import HttpResponse
from books.models import Books
def index(request):
    books_list = Books.objects.all()
    return HttpResponse(books_list)
-and then just hit refresh on your browser. (Remember: we didn't stop the server).
You should see all of the books in one long line. It looks bad, but it works.
Next, we're going to work with templates, which will allow us to easily create a much more readable output.

Start by making a new directory in the django directory, outside of the project, called templates. Within that directory, make a directory called books.

Next open up, scroll down to TEMPLATE_DIRS and add the template directory-

Yes, those are forward slashes. ### Now create a new file in your *temples\books* directory. Save it as index.html and add the following code-
<h1>My Fab Book Collection</h1>
{% if books_list %}
{% for b in books_list %}
    <li>{{b.title}} | {{}} | {{}}</li>
{% endfor %}
{% endif %}

Open again and make it looks like this-

from django.http import HttpResponse
from books.models import Books
from django.template import Context, loader      
def index(request):
  books_list = Books.objects.all()
  t = loader.get_template('books/index.html')
  c = Context({'books_list': books_list,})
  return HttpResponse(t.render(c))
Basically, the loader is the path to the template we created, which then gets assigned to the Python object via the Context dictionary.

Save the file. Run the server. Refresh the http://localhost:8000/books page. There's the books. Looks a little better, too.

I know I said that I'd show to make it so a non-administrator can add data to the database - but I just realized that this would be another lesson in itself. So, I'm going to stop here. Feel free to view the Django Tutorial to learn how to add that functionality to your application.
In fact, the whole point to these tutorials is for you to get started with the Django tutorial. I bounced around a bit but I hope that you can now go through the tutorial a bit easier now that you have a starting off point.
Thanks for watching. See you next time.






















  work with database command 

syncdb create the required tables as follows: 

 C:\DjangoProjects\mysite>python syncdb 


Django is a free web framework written in python. It's very to use!

Let's create a blog in less then 10min!

1. First create a project startproject blog

Switch to folder "blog"

Start the dev server

./manage runserver 8000

Type: in browser

2. Create a file ""

 Create a model

from django.db import models

class Blog(models.Model):
    title = models.CharField(max_length=32)
    date = models.DateTimeField(auto_now_add=True)
    text = models.TextField()

3. Setup your database settings

Edit the file ""

    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'test',                      # Or path to database file if using sqlite3.
        'USER': 'test',                      # Not used with sqlite3.
        'PASSWORD': 'password',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.

4. "Install" the blog models

Add "blog" to INSTALLED_APPS

    'blog', #<-------------------------------
    # Uncomment the next line to enable the admin:

5. Create a templates

Create folder "templates".

Switch to folder "templates". Create file "index.html"

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
        <title>My Blog</title>

    <div id="content">
    {% block content %}
    {% endblock %}

6. Setup the templates path
Edit "" file.
Import os at the top
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(os.path.dirname(__file__),'templates'), # creates a absolute path

7. Create the blog tables

Run "./manage syncdb"

It will create the blog tables.
It will ask you to create a superuser, follow the instructions

8. Add a url pattern

Edit file ""

urlpatterns = patterns('',
    # Example:
    # (r'^blog/', include('')),
    (r'^, 'blog.views.index'), #<------------------- index/root entry

    # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
    # to INSTALLED_APPS to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    #(r'^admin/', include(,

9. Create a view

Create a file ""
from django.shortcuts import render_to_response

def index(request):
    return render_to_response('index.html', locals())

Run the dev server: ./manage runserver 8000

10. Activate the admin

Uncomment "django.contrib.admin" in INSTALLED_APPS
    # Uncomment the next line to enable the admin:
    'django.contrib.admin', #<<<------- uncommented

Edit "" file

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin #<<< uncomment this
admin.autodiscover() #<<< uncomment this

urlpatterns = patterns('',
    (r'^, 'blog.views.index'),
    # Uncomment the next line to enable the admin:
    (r'^admin/', include(, #<<< uncomment this

Run ./manage syncdb

11. Activate the module in admin

Create file ""

from django.contrib import admin
from blog.models import Blog

class AdminBlog(admin.ModelAdmin):
    pass, AdminBlog)

Type "" in your browser

Login as superuser which you choose before

Click on "Add" and create some posts

12. Fill the view with logic

from django.shortcuts import render_to_response
from blog.models import Blog

def index(request):
    entries = Blog.objects.all()
    return render_to_response('index.html', locals())

13. Show it in template

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
        <title>My Blog</title>

    <div id="content">
    {% block content %}
        {% for e in entries %}
            {{ e.title }}<br/>
            {{ }}<br/>
            {{ e.text }}<br/>
        {% endfor %}

    {% endblock %}

Type in your browser and you see your blog!

Every view renders a webpage. For this Django has a own template system.
1. First we create a templates folder in our root project and change into it
2. Now create a folder what ever you like, the best would be the name of the application, like homepage and change into it
3. When create a index.html, to make clear that is the entry point of this application template
4. Create your our html template or for example:

    <title>My Blog Index</title>
    <h3>Index Page</h3>

5. Open the global settings
6. Import on the top the os module and modify the TEMPLATE_DIRS variable and add the path, for example
import os
DEBUG = True
    # ('Your Name', ''),
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join( os.path.dirname(__file__), 'templates' ),)

7. Open the file
8. Import the render_to_response function. This will do the job for you, parse a template and return a valid HttpResponse object.
9. Use the render_to_response in the view, for example
from django.shortcuts import render_to_response
def index(request):
    return render_to_response('homepage/index.html')  
10. The first parameter is the template.
11. Start the dev server: python runserver



Adding additional Django apps to your GeoNode Project

Since GeoNode is based on Django, your GeoNode project can be augmented and enhanced by adding additional third-party pluggable Django apps or by writing an app of your own.
This section of the workshop will introduce you to the Django pluggable app ecosystem, and walk you through the process of writing your own app and adding a blog app to your project.

Django pluggable apps

The Django app ecosystem provides a large number of apps that can be added to your project. Many are mature and used in many existing projects and sites, while others are under active early-stage development. Websites such as Django Packages provide an interface for discovering and comparing all the apps that can plugged in to your Django project. You will find that some can be used with very little effort on your part, and some will take more effort to integrate.

Adding your own Django app

Let’s walk through the an example of the steps necessary to create a very basic Django polling app to and add it to your GeoNode project. This section is an abridged version of the Django tutorial itself and it is strongly recommended that you go through this external tutorial along with this section as it provides much more background material and a signficantly higher level of detail. You should become familiar with all of the information in the Django tutorial as it is critical to your success as a GeoNode project developer.
Throughout this section, we will walk through the creation of a basic poll application. It will consist of two parts:
  • A public site that lets people view polls and vote in them.
  • An admin site that lets you add, change, and delete polls.
  1. Create app structure
    Since we have already created our GeoNode project from a template project, we will start by creating our app structure and then adding models:
    $ python startapp polls
    That’ll create a directory polls, which is laid out like this:
    This directory structure will house the poll application.
  2. Add models
    The next step in writing a database web app in Django is to define your models—essentially, your database layout with additional metadata.
    In our simple poll app, we’ll create two models: polls and choices. A poll has a question and a publication date. A choice has two fields: the text of the choice and a vote tally. Each choice is associated with a poll.
    These concepts are represented by simple Python classes.
    Edit the polls/ file so it looks like this:
    from django.db import models
    class Poll(models.Model):
        question = models.CharField(max_length=200)
        pub_date = models.DateTimeField('date published')
        def __unicode__(self):
            return self.question
    class Choice(models.Model):
        poll = models.ForeignKey(Poll)
        choice = models.CharField(max_length=200)
        votes = models.IntegerField()
        def __unicode__(self):
            return self.choice
    That small bit of model code gives Django a lot of information. With it, Django is able to:
    • Create a database schema (CREATE TABLE statements) for this app.
    • Create a Python database-access API for accessing Poll and Choice objects.
    But first we need to tell our project that the polls app is installed.
    Edit the <my_geonode>/ file, and update the INSTALLED_APPS setting to include the string “polls”. So it will look like this:
        # Apps bundled with Django
        #Third party apps
        # <snip>
        # GeoNode internal apps
        # My GeoNode apps
    Now Django knows to include the polls app. Let’s run another command:
    $ python syncdb
    The syncdb command runs the SQL from sqlall on your database for all apps in INSTALLED_APPS that don’t already exist in your database. This creates all the tables, initial data, and indexes for any apps you’ve added to your project since the last time you ran syncdb. syncdb can be called as often as you like, and it will only ever create the tables that don’t exist.
    GeoNode uses south for migrations ...
  3. Add Django Admin Configuration
    Next, let’s add the Django admin configuration for our polls app so that we can use the Django Admin to manage the records in our database. Create and edit a new file called polls/ and make it look like the this:
    from polls.models import Poll
    from django.contrib import admin
    Run the development server and explore the polls app in the Django Admin by pointing your browser to http://localhost:8000/admin/ and logging in with the credentials you specified when you first ran syncdb.
    You can see all of the other apps that are installed as part of your GeoNode project, but we are specifically interested in the Polls app for now.
    Next we will add a new poll via automatically generated admin form.
    You can enter any sort of question you want for initial testing and select today and now for the publication date.
  4. Configure Choice model
    The next step is to configure the Choice model in the admin, but we will configure the choices to be editable in-line with the Poll objects they are attached to. Edit the same polls/ so it now looks like the following:
    from polls.models import Poll, Choice
    from django.contrib import admin
    class ChoiceInline(admin.StackedInline):
        model = Choice
        extra = 3
    class PollAdmin(admin.ModelAdmin):
        fieldsets = [
            (None,               {'fields': ['question']}),
            ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
        inlines = [ChoiceInline], PollAdmin)
    This tells Django that Choice objects are edited on the Poll admin page, and by default, provide enough fields for 3 choices.
  5. Add/edit poll
    You can now return to the Poll admin and either add a new poll or edit the one you already created and see that you can now specify the poll choices inline with the poll itself.
  6. Create views
    From here, we want to create views to display the polls inside our GeoNode project. A view is a “type” of Web page in your Django application that generally serves a specific function and has a specific template. In our poll application, there will be the following four views:
    • Poll “index” page—displays the latest few polls.
    • Poll “detail” page—displays a poll question, with no results but with a form to vote.
    • Poll “results” page—displays results for a particular poll.
    • Vote action—handles voting for a particular choice in a particular poll.
    The first step of writing views is to design your URL structure. You do this by creating a Python module called a URLconf. URLconfs are how Django associates a given URL with given Python code.
    Let’s start by adding our URL configuration directly to the that already exists in your project at <my_geonode>/ Edit this file and add the following lines after the rest of the existing imports around line 80:
    url(r'^polls/$', 'polls.views.index'),
    url(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),
    url(r'^polls/(?P<poll_id>\d+)/results/$', 'polls.views.results'),
    url(r'^polls/(?P<poll_id>\d+)/vote/$', ''),
    Eventually we will want to move this set of URL configurations inside the URLs app itself, but for the sake of brevity in this workshop, we will put them in the main for now. You can consult the Django tutorial for more information on this topic.
    Next write the views to drive the URL patterns we configured above. Edit polls/ to that it looks like the following:
    from django.template import RequestContext, loader
    from polls.models import Poll
    from django.http import HttpResponse
    from django.http import Http404
    from django.shortcuts import render_to_response
    def index(request):
        latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
        return render_to_response('polls/index.html',
            RequestContext(request, {'latest_poll_list': latest_poll_list}))
    def detail(request, poll_id):
            p = Poll.objects.get(pk=poll_id)
        except Poll.DoesNotExist:
            raise Http404
        return render_to_response('polls/detail.html', RequestContext(request, {'poll': p}))
    def results(request, poll_id):
        return HttpResponse("You're looking at the results of poll %s." % poll_id)
    def vote(request, poll_id):
        return HttpResponse("You're voting on poll %s." % poll_id)
    We have only stubbed in the views for the results and vote pages. They are not very useful as-is. We will revisit these later.
    Now we have views in place, but we are referencing templates that do not yet exist. Let’s add them by first creating a template directory in your polls app at polls/templates/polls and creating polls/templates/polls/index.html to look like the following:
    {% if latest_poll_list %}
        {% for poll in latest_poll_list %}
            <li><a href="/polls/{{ }}/">{{ poll.question }}</a></li>
        {% endfor %}
    {% else %}
        <p>No polls are available.</p>
    {% endif %}
    Next we need to create the template for the poll detail page. Create a new file at polls/templates/polls/detail.html to look like the following:
    <h1>{{ poll.question }}</h1>
    {% for choice in poll.choice_set.all %}
        <li>{{ choice.choice }}</li>
    {% endfor %}
    You can now visit http://localhost:8000/polls/ in your browser and you should see the the poll question you created in the admin presented like this.
  7. Update templates
    We actually want our polls app to display as part of our GeoNode project with the same theme, so let’s update the two templates we created above to make them extend from the site_base.html template we looked at in the last section. You will need to add the following two lines to the top of each file:
    {% extends 'site_base.html' %}
    {% block body %}
    And close the block at the bottom of each file with:
    {% endblock %}
    This tells Django to extend from the site_base.html template so your polls app has the same style as the rest of your GeoNode, and it specifies that the content in these templates should be rendered to the body block defined in GeoNode’s base.html template that your site_base.html extends from.
    You can now visit the index page of your polls app and see that it is now wrapped in the same style as the rest of your GeoNode site.
    If you click on a question from the list you will be taken to the poll detail page.
    It looks like it is empty, but in fact the text is there, but styled to be white by the Bootswatch theme we added in the last section. If you highlight the area where the text is, you will see that it is there.
Now that you have walked through the basic steps to create a very minimal (though not very useful) Django app and integrated it with your GeoNode project, you should pick up the Django tutorial at part 4 and follow it to add the form for actually accepting responses to your poll questions.
We strongly recommend that you spend as much time as you need with the Django tutorial itself until you feel comfortable with all of the concepts. They are the essential building blocks you will need to extend your GeoNode project by adding your own apps.

Adding a 3rd party blog app

Now that we have created our own app and added it to our GeoNode project, the next thing we will work through is adding a 3rd party blog app. There are a number of blog apps that you can use, but for purposes of this workshop, we will use a relatively simple, yet extensible app called Zinnia. You can find out more information about Zinnia on its website or on its GitHub project page or by following its documentation. This section will walk you through the minimal set of steps necessary to add Zinnia to your GeoNode project.
  1. Install Zinnia
    The first thing to do is to install Zinnia into the virtualenv that you are working in. Make sure your virtualenv is activated and execute the following command:
    $ pip install django-blog-zinnia
    This will install Zinnia and all of the libraries that it depends on.
  2. Add Zinnia to INSTALLED_APPS
    Next add Zinnia to the INSTALLED_APPS section of your GeoNode projects file by editing <my_geonode>/ and adding ‘django.contrib.comments’ to the section labeled “Apps Bundled with Django” so that it looks like the following:
    # Apps bundled with Django
    And then add the tagging, mptt and zinnia apps to the end of the INSTALLED_APPS where we previously added a section labeled “My GeoNode apps”. It should like like the following:
    # My GeoNode apps
  3. Synchronize models
    Next you will need to run syncdb again to synchronize the models for the apps we have just added to our project’s database. This time we want to pass the --all flag to syncdb so it ignores the schema migrations. Schema migrations are discussed further in GeoNode’s documentation, but it is safe to ignore them here.
    $ python syncdb --all
    You can now restart the development server and visit the Admin interface and scroll to the very bottom of the list to find a section for Zinnia that allows you to manage database records for Categories and Blog Entries.
  4. Configure project
    Next we need to configure our project to add Zinnia’s URL configurations. Add the following two URL configuration entries to the end of <my_geonode>/
    url(r'^blog/', include('zinnia.urls')),
    url(r'^djcomments/', include('django.contrib.comments.urls')),
    If you visit the main blog page in your browser at http://localhost:8000/blog/ you will find that the blog displays with Zinnia’s default theme as shown below.
    If you are not able to visit the main blog page, you will have to set USE_TZ = True in Restart the server and try again!
    This page includes some guidance for us on how to change the default theme.
  5. Change default theme
    The first thing we need to do is to copy Zinnia’s base.html template into our own project so we can modify it. When you installed Zinnia, templates were installed to /var/lib/geonode/lib/python2.7/site-packages/zinnia/templates/zinnia/. You can copy the base template by executing the following commands:
    $ mkdir <my_geonode>/templates/zinnia
    $ cp /var/lib/geonode/lib/python2.7/site-packages/zinnia/templates/zinnia/base.html <my_geonode>/templates/zinnia/
    Then you need to edit this file and change the topmost line to read as below such that this template extends from our projects site_base.html rather than the zinnia skeleton.html:
    {% extends "site_base.html" %}
    Since Zinnia uses a different block naming scheme than GeoNode does, you need to add the following line to the bottom of your site_base.html file so that the content block gets rendered properly:
    {% block body %}{% block content %}{% endblock %}{% endblock %}
    You can see that there are currently no blog entries, so let’s add one. Scroll to the bottom of the interface and click the Post an Entry link to go to the form in the Admin interface that lets you create a blog post. Go ahead and fill out the form with some information for testing purposes. Make sure that you change the Status dropdown to “published” so the post shows up right away.
    You can explore all of the options available to you as you create your post, and when you are done, click the Save button. You will be taken to the page that shows the list of all your blog posts.
    You can then visit your blog post/entry at http://localhost:8000/blog/.
    And if you click on the blog post title, you will be taken to the page for the complete blog post. You and your users can leave comments on this post and various other blog features from this page.
  6. Integrate app into your site
    The last thing we need to do to fully integrate this blog app (and our polls app) into our site is to add it to the options on the navbar. To do so, we need to add the following block override to our Projects site_base.html:
    {% block extra-nav %}
    <li id="nav_polls">
        <a href="/polls/">Polls</a>
    <li id="nav_blog">
        <a href="{% url 'zinnia_entry_archive_index' %}">Blog</a>
    {% endblock %}
At this point, you could explore options for tighter integration between your GeoNode project and Zinnia. Integrating blog posts from Zinnia into your overall search could be useful, as well as including the blog posts a user has written on their Profile Page. You could also explore the additional plugins that go with Zinnia.

Adding other apps

Thursday, 4 June 2015

SocialTurn – Open Source PHP Buffer App Clone

Social Media Publishing for Teams
SocialTurn makes it easy for teams to publish to social media. Drop the manual sharing of social passwords to each team member, and worrying about your security and get SocialTurn, the easy and free way to publish social updates for your whole team. SocialTurn is a PHP/mySQL based Buffer clone.
1. Social
- Auto schedule social posts depending on day and time
- Share important posts via multiple accounts
- Use suggestions for posting generic updates
- Quick and simple updates and management
2. Team
- Manage multiple team members
- Assign privileges to members
- Give access to specific Twitter/Facebook accounts to each user
- Invite a new team member directly via email
3. Connect
- Manage multiple Twitter & Facebook accounts
- Reconnect/delete old accounts with ease
Launch SocialTurn – Buffer Clone Demo
1. PHP 5+
2. mySQL

1. Allow users to post questions and answers
2. Points system similar to StackOverflow
3. Ability to post an article as a knowledge-base (for corporates)
4. Ability to lock site to registered users only
5. Clean CSS layout
6. Works in all major browsers
Launch Qwench – StackOverflow Clone Demo
Qwench StackOverflow Clone
1. PHP 4+
2. mySQL
Getting Started
Download and follow the instructions in README.txt file

7 simple social skills that will make you more likable


1. Keep your timing in check
Ready. Set. Go! Type "set timer to 13 minutes and 13 seconds" and the clock immediately starts to wind down. This is a quick solution if you're waiting to make an important phone call or pick the kids up from school in a few minutes. The timer is especially useful if you don't have your smartphone handy to check the time or use the built-in stopwatch. google trick


1. Make eye contact.

"It is an idiotically simple thing, but it remains one of the most impactful life hacks around," writes Quora user Brad Porter. "The most attractive quality in a person is confidence. But 'be confident' is not very good advice. Instead, find the best proxy for confidence, in terms of interactive behavior. And that's eye contact."
Start this habit immediately, says Porter. It requires no practice or special skill; just the commitment to meet someone's gaze and look them in the eye while conversing.  

2. Put your smartphone in your pocket.

And keep it there until your conversation or meeting is over. Basil Chiasson puts it simply: "Pay attention. Look at them. Stop what you're doing. No interruptions."
This is another simple, yet effective, habit that can be executed immediately and does not require any effort or skill.

3. Call people by name.

The next time someone greets you by name or uses your name mid-conversation, remember how great that feels.
If you have trouble putting names to faces, try different strategies, such as writing them down or using imagery or rhymes associated with the name. Quora user Howard Lee suggests repeating their name verbally when you're first introduced, and then twice more in your head.
Smiling(Fabio Dellutri/Flickr)

4. Smile.

Don't underestimate the power of smiling.
Additionally, laugh and tell jokes, recommends Quora user Craig Fraser. People unconsciously mirror the body language of the person they're talking to; if you want to be likable, use positive body language and people will naturally return the favor.  

5. Give a firm handshake.

"Not too hard, certainly not limp and soft, and with no dominance play," writes Tony Vincent.
Research shows that people decide whether or not they like you within seconds of meeting you. A firm handshake contributes largely to that first impression, as do strong posture and positive body language.

6. Listen.

Listen more than you speak, says Quora user Mark Bridgeman: "You have two ears, only one mouth. That's the ratio you should use them with." 
conversation monk(Flickr User Oli Young)

7. Don't just listen — actively listen. 

Simply hearing words doesn't cut it. Likable people truly listen to the person they're talking to.
Active listening requires four steps, writes Chiasson: Hearing, interpreting, evaluating, and responding.
Step one requires dropping what you're doing and paying attention. Next, "paraphrase what you've heard and ask clarifying questions," she suggests. Evaluating means steering clear of quick judgment and jumping to conclusions: "Make sure you have all the pertinent information before forming or expressing an opinion." Finally, "give feedback to let the speaker know that you heard them," she writes. 

How to Fix/Solve the Website Screen Resolution Problem ?

For long times I have been looking for solution to fix my

Website Resolution problem

. Initially I tried all the responsive design and all that, But nothing works. Then a thought pop up in my Mind about

adjusting website resolution

as per Screen Size of any resolution. Solution is even more easier than it look.
CSS Provides property named scale which can scale the size(width x height) of any element in the document.
For example, <div id ="t_div"></div>
Now we can scale the size of the division as follow:

-moz-transform:scale(1.5,1.5); //for Firefox
Above code will increase the size of division by x1.5 .
First of all suppose that you have your Website designed for fix size say, WIDTH x HEIGHT(e.g. 1280 x 768, 1366 x 768 etc.).
Now we will use this property of CSS to scale our website's main Tag(<html>) to adjust size according to screen size.
But we have to scale <html> tag dynamically according to screen size. For this we will use jQuery-a javascript library, to

apply CSS Property dynamically

. Step - 1: Apply the following CSS to your index page.

//set height and width property at its maximum size in 'px' value.
step - 2: Link the jQuery to your link can download the local copy of jQuery OR link the online jQuery by using following tag.
<script src=""></script>
step - 3: Now copy the following code to in your javascript.

$(document).ready(function() {

//Other code ...

/*HEIGHT and WIDTH below is your screen size not the your browser's
inner Size. AND if your width is 1280px then replace WIDTH by 1280.0 
(Note 0 after point)in the code below and same for HEIGHT.*/

factor_x = ($(window).width()) / WIDTH;
factor_y = ($(window).height( ))/HEIGHT;

//For Firefox
//For Google Chrome

//For Opera


After doing this thing properly, Check your Website for various resolution. It should work.
What we are doing is scaling the <html> tag Up or Down, keeping aspect ratio of screen constant.

Tuesday, 2 June 2015

Yureka Defects, Cons, Problems and Solutions

 There is also software based bug for network mode. I have personally experienced this i.e. network mode doesn’t change in reality even if I select 3g mode. So, to force your particular sim card to switch to 3g only mode, first deactivate/disable other sim card on Yureka from setting> sim cards menu. Then dial *#*#4636#*#* > phone information. Tap on Turn off radio button and wait until the button reads turn on radio. Select WCDMA only from dropdown menu above the button. Wait a few seconds. Now tap on Turn on Radio button. Your desired sim card will successfully connect to 3G network. Now go to settings and sim card option and activate the disabled sim card as well. You may need to manually search for network signal if no network is shown. Also you may need to restart the device. If in 3g mode, your phone doesn’t connect to internet, Go to apn setting to ensure correct apn is selected. Sometimes APN menu might not show any installed network settings, in such case, just restart the handset. All these network related issues will be hopefully solved in the next Yureka ota software/firmware update.

How To Fix Micromax Yureka Heating Problem, Solution --- by Amey Bansod 19/02/2015 | 1:31 What you have to do is follow the steps given below. Go into the settings -> apps -> Media Storage Device. Force stop it. Clear the Cache Clear the data. Disable it. Restart the phone. Enable it Restart the phone If you are again seeing the heating problem then again go into the settings -> apps -> Media Storage Device. Force stop it. Clear the data, Clear the Cache -> Restart the phone. If issue appears again then again follow the steps given above. You’ve to do this till you stop facing heating problem. After applying this fix, my friend is getting the battery life of 1 and half day for Yu. :)

1. in-call display issue/proximity sensor bug: Some of the Yureka units have been plagued by this problem (I have not faced this but my friend did on his yu phone). During call, the display turns off, goes black/blank and never wakes, even if you press power button, until call disconnects. This seems to be proximity sensor issue. Some of the users of affected phones have already reported this issue to Yu customer support team and on official Yu forum. The support team is working on releasing software based fix. So, wait for OTA software update and install firmware ota update whenever available. While some users report this to be hardware issue, not a software bug. One of the affected users has suggested a fix, citing poor assembly of components or dirt trapped near proximity sensor as probable cause, that the three screws on the back should be tightened and the user should try blowing air near 3.5mm audio jack. So you may try this method to fix this particular issue. You may also return the defective unit to amazon if you’ve not surpassed 10-days of usage and get refund so you could buy Yureka in its next sale, as Amazon doesn’t provide replacement, but amazon does host exclusive sale (one day prior to the scheduled sale) for those amazon accounts in which Yureka was returned or the order was cancelled. In fact, one of my friends was suggested by Yureka customer support to return the defective unit and try buying in the next sale, or you may request for support-service under warranty.
Update: Try fixing proximity sensor issues on Yureka by dialing *#*#7769#*#* and then start calibration. While it is being run, place your hand over proximity sensor i.e. top part of your phone and then hit on stop button after sometime. Report if this solves your issue.
2. Yureka sim card slot issues– Some of the users (including the author of this article) have also faced problems with the second sim card slot. Issues like sim card not being detected or no network signal when sim inserted in second sim card slot. If sim card is not detected in the 2nd sim slot, exchange the sim cards with the first sim slot. Try adjusting sim card little sideways within the slot to ensure the chip on sim card is properly in contact with the points in sim card slot of your phone. If none of the two methods works, get a new micro-sim card from your operator as those normal sim cards cut using micro-sim cutter face detection issues. For no network signal issue, go to network settings and do manual search for network, then select the network of your sim card. This fix has been helpful for some users.
There is also software based bug for network mode. I have personally experienced this i.e. network mode doesn’t change in reality even if I select 3g mode. So, to force your particular sim card to switch to 3g only mode, first deactivate/disable other sim card on Yureka from setting> sim cards menu. Then dial *#*#4636#*#* > phone information. Tap on Turn off radio button and wait until the button reads turn on radio. Select WCDMA only from dropdown menu above the button. Wait a few seconds. Now tap on Turn on Radio button. Your desired sim card will successfully connect to 3G network. Now go to settings and sim card option and activate the disabled sim card as well. You may need to manually search for network signal if no network is shown. Also you may need to restart the device. If in 3g mode, your phone doesn’t connect to internet, Go to apn setting to ensure correct apn is selected. Sometimes APN menu might not show any installed network settings, in such case, just restart the handset. All these network related issues will be hopefully solved in the next Yureka ota software/firmware update.
3. Camera – If you’re getting “can’t connect to camera” error (I haven’t faced this issue, but some users reported this). Just hold camera icon and drag it to app info, hit on clear cache/data button and then launch camera. It should work.
3. Sound Volume – Low Sound. Playing Music on Yureka loudspeaker will not appeal to many as the sound output is low. Sometimes sound plays muffled as well, depending upon the type of track you’re playing. If the sound output is distorting kinda, Go to audiofx app and disable it on speaker mode.
In-call sound is great but if you get low sound in earpiece, make sure in-call volume is at its peak. There is volume controls bug as well for in-call sound. During call, if the user tries to lower the volume, the volume slider moves but the volume level in reality is not lowered. I have also faced this bug. So, wait for software update, hopefully, these issues will be fixed.
4. Display preference– Display of Yureka is awesome in my opinion, looks deep, dark, rich in colors, kinda saturated as well. However you may not like it. Well, you can lessen such effect by turning off adaptive backlight to increase display brightness and disabling color enhancement in display in settings. Try these and see if the new changed display properties suit your eyes.
5. 99% battery bug – The battery is stuck at 99% (on my Yureka as well). It’s a software bug. The percentage display in status bar never goes to 100% but the phone is fully charged. Wait for upcoming software ota update.
6. Yureka Earphone/Headphone bug – Sometimes, after inserting 3.5mm audio jack of your headphone or earphone jack, Yureka doesn’t detect it. If you play music, it plays on phone loudspeaker instead of routing the sound to headset. On the other hand, if playing in earphone, it doesn’t play on loudspeaker even after removing earphone. In a nutshell, it sometimes fails to detect plugging or unplugging of headphone jack. The author of this post has also encountered this problem. If it doesn’t detect plugging of your headphone jack, just unplug it and plug it again but this time do it faster and make sure it is fully inserted in audio jack. If it doesn’t detect unplugging of earphone jack and you’re unable to play music on loudspeaker, just plug your earphone and unplug it again and then it will detect unplugging and then you’ll be able to play your audio file on loudspeaker as well. If none of the suggested methods work, rebooting/restarting your device by pressing power button and selecting the appropriate option is your last resort, and it definitely works. These issues are software related bugs so it’ll be probably fixed in ota update.
7. Dual sim dialer – The default dialer in Yureka doesn’t have two call buttons, one for each sim card. Instead, you can set in settings>sim cards>Voice calls> Always ask. Here you can also set sim1 or sim2 as the default for all outgoing voice calls. Always ask preference is good, but it makes the user tap once more to select the sim card after hitting on call button in dialer. If you set a particular sim as the default and for some reason you want to make a particular call from not-default sim card, you need to go to sim card setting to alter the default or select always ask as the option. So, this is hassling process. To solve this, we either need two call buttons in dialer for each sim card or a toggle button in notification toggle window to easily change/switch the default sim card. We hope such improvement to be made in future Cyanogen software update.
8. Certain Apps crashing: If PlayStore, gallery or some other inbuilt apps crashes, I have not experienced these kind of issues, the solution is to clear cache/data of that particular app by holding the app icon and dragging it to app info label and then clearing its cache. I do have experienced “android.process.acore stopped working” error but one or two times only. If that doesn’t help, factory reset might help.
9. Battery backup issues: Some users have also reported horrible battery life on Yureka. This could be due to several reasons. So, the best way to solve this is to find whether there is defect in battery or due to some software based reasons. Make sure your phone is set to balanced performance mode, and no third-party apps keep it awake all time. Hopefully, software update might further increase battery life. Do tell us how much of battery juice you’re able to get on your Yureka in comment section below.
10. Unable to access internet/mobile data on Yureka: Some users are also not able to use mobile data to access internet on Yureka. For them, only whatsapp is working, webpages don’t open in browser. TO troubleshoot this issue, Go to setting>mobile networks>Access points and make sure your network apn setting profile is listed and selected there. If it isn’t, restart your handset and then create a new apn profile yourself. If apn profile is listed, enter that profile and make sure there is nothing written in proxy/port option of the apn profile (delete whatever is written in proxy/port option of apn profile). This should solve your mobile data based internet issues.
10. You tell me: If you’re facing any such issues, or discovered some new problems or bugs in Yureka, do notify us in comments. We’d try to help you solve the same or report it. Also read our article on Yureka top 10 plus tips