Useful videos:

sentdex videos

heroku deployment

Start Project

1. start virtual environment in your favourite folder or make a new one

virtualenv .

2. activate virtual environment

source bin/activate

3. if you haven't installed django

sudo pip install django==1.8

4. create a djano project, you can put any name startproject trydjango18

for sake of easiness rename it to src (which means source code) 5. got to src and runserver

python runserver


1. migrations is change how we store data

python migrate

Admin & Superuser

1. migrate and create admin (syncdb is not there in 1.9)

python syncdb

2. to directly create superuser after migrate

python createsuperuser

3. go and add /admin to the url, where you can login as admin


apps in django are little functions that build up your entire django webapp (project). These are like which does one function at its best.

1. create new app

python startapp newsletter

First view and URL routing

1. in configfolder/, r is root url, 2nd arg is which should be executed

url(r'^$','newsletter.views.home', name='home'),  #set a root page view
url(r'^newsletter','newsletter.views.home', name='home'), #if requested with/newsletter views.home will be called and that template will be viewed

2. defining that view in newsletter/

def home(request):
        return render(request,"home.html",{})
#if got a request return home.html template, as simple as that

Django Settings Overview

1. goto configfolder/

import os # helps us to work with any os, operating system independent
BASE_DIR #is directory of project where is, this is root of project
SECURITY_KEY #security thing
DEBUG #security thing
ALLOWED_HOSTS # Production stuff like
MIDDLEWARE_CLASSES # middleware is like b/w request and response
ROOT_URL_CONF # this tells what urls to work with which points
DATABASES # we r using sqlite3 others mysql and postgresql

LANGUAGE_CODE #can be changed
STATIC_URL # since images and css cant be used directly we use static directory

Configuration for Templates configfolder/


2. Create templates folder in newsletter and home.html in templates then run the server. you will get blank page.

thats it it loads apps if you put installed_apps


1. create templates folder in src or root, and home.html in root

2. in the template directories define the path

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, "templates")],# see in base/templates


1. Models are classes we define where the a model is like an action getting the data and it will transfer it to database. Eg: signup model

class SignUp (models.Model):
        timestamp=models.DateTimeField(auto_now_add=True, auto_now=False)
        updated=models.DateTimeField(auto_now_add=False, auto_now=True)

        def __unicode__ (self): #__str__ in python3.3

2.Add the app name in the installed apps in of configfolder


3. run the migration, run this when ever changed

python makemigrations


1. add the following snippet to in the app

from .models import SignUp

so that, it will be registered, and admin can view the database tables

2. add the following snippet to in the app, list_display is to view all kind of details you will be able to watch

# Register your models here.
from .models import SignUp
class SignUpAdmin(admin.ModelAdmin):
        class Meta:

Wiki: mallasrikanth/django (last edited 2016-01-02 07:12:47 by mallasrikanth)