Roshan Book

My Tech Notebook

Revision before creating an app

How Django process your request


Starting your project – startproject mysite

Running sever – python runserver 8080

Sync Db – python syncdb

Set up database type in

Starting an app– python startapp polls

Add app to under “installed app”

A Sample model to revise :

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.question
Sync db - python syncdb
See the sql -python sql polls
Getting into your app shell : python shell
InSide shell:
from polls.models import Poll, Choice
For more command visit here
Activating the admin site

Activate the admin site

The Django admin site is not activated by default – it’s an opt-in thing. To activate the admin site for your installation, do these three things:

  • Add "django.contrib.admin" to your INSTALLED_APPS setting.
  • Run python syncdb. Since you have added a new application toINSTALLED_APPS, the database tables need to be updated.
  • Edit your mysite/ file and uncomment the lines that reference the admin – there are three lines in total to uncomment. This file is a URLconf; we’ll dig into URLconfs in the next tutorial. For now, all you need to know is that it maps URL roots to applications. In the end, you should have a file that looks like this:
    from django.conf.urls.defaults import patterns, include, url
    # Uncomment the next two lines to enable the admin:
    from django.contrib import admin
    urlpatterns = patterns('',
        # Examples:
        # url(r'^$', 'mysite.views.home', name='home'),
        # url(r'^mysite/', include('')),
        # Uncomment the admin/doc line below to enable admin documentation:
        # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
        # Uncomment the next line to enable the admin:
        url(r'^admin/', include(,

    (The bold lines are the ones that needed to be uncommented.)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: