Innovate anywhere, anytime Your cloud-based dev studio.

Creating Django App



Django is a high-level Python Web framework that encourages rapid development.
Install django in virtualenv to keep it safe from messing around with the other versions you may have.
$ virtualenv env
$ env/bin/activate
$ pip install django

If Django is installed, you can see the version of our installation by running following command 

    $ python -c "import django; print(django.get_version())"

otherwise you get an error “No module named django”

Creating a Project:

If this is your first time using Django, you’ll need to auto-generate code that establishes a Django Project
 A collection of settings, 
 Including database configuration, 
 Django-specific options and application-specific settings.

With the following command:

$ startproject myproject

This will Create "myproject" directory in your current directory.The above command(startproject) creates

    |- myproject/

The outer "myproject/" root directory is where your project is stored.

It is automatically created in each Django project. is a thin wrapper around before delegating to puts your project’s package on sys.path,Sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your project’s file,  Calls django.setup() to initialize various internals of Django.

The inner "myproject/" directory is the actual Python package for your project.


An empty file that tells Python, this directory should be considered a Python package.


Settings/configuration for this Django project. 


The URL declarations for Django project


An entry-point for WSGI-compatible web servers to serve your project.

Database setup:

By default, SQLite is included in Python, so you won’t need to install anything to support your database.If you wish to use another database, install the appropriate database, and change ENGINE and NAME keys in the DATABASES to match your database connection settings

ENGINE – example: 'django.db.backends.sqlite3'

NAME – The name of your database.


INSTALLED_APPS holds the names of all Django applications that are activated in this Django instance. By default, INSTALLED_APPS contains the following applications:

django.contrib.admin – The admin site. django.contrib.auth – An authentication system. django.contrib.contenttypes – A framework for content types. django.contrib.sessions – A session framework. django.contrib.messages – A messaging framework. django.contrib.staticfiles – A framework for managing static files.

Before using these applications you need to create a database by running the following command

$ python syncdb

The migrate command looks at the INSTALLED_APPS setting and creates necessary database tables according to the database settings in your myapplication/ file.

Creating an App:

To create your app, make sure you’re in the same directory as and type this command:

$ python startapp myapp   #This creates a directory myapp


In our myapp application,create one Model: An Article has publication_date,title and content.

Edit the myapp/ file


from django.db import models
  class Article(models.Model):
    publication_date = models.DateField()
    title = models.CharField(max_length=50)
    content = models.TextField(max_length=200)

Activating models: First you need to tell your project that "myapp" app is,Include your app name(myapp) in INSTALLED_APPS of file

INSTALLED_APPS = ( 'django.contrib.admin',

Now,run following command:

$ python syncdb

By running makemigrations, you’re telling Django that you’ve made some changes to your models. Now, run migrate again to create those model tables in your database:

For writting view. Open the file myapp/ and write your code:

from django.http import HttpResponse
def index(request):
        return HttpResponse("Hello,You're at the myapp index.")

To call the view, we need to map it to a URL we need a URLconf.To create a URLconf in the "myapp" directory, create a file called
Now your app looks like:



from django.conf.urls import patterns, url from polls import views

urlpatterns = patterns('myapp.views', url(r'^$', index, name='index'),)

The next step is to point the root URLconf at the myapp.urls module. In myproject/ insert an include()



from django.conf.urls import patterns, include, url

from django.contrib import admin

urlpatterns = patterns('', url(r'^myapp/', include('myapp.urls')), url(r'^admin/', include(,   )

The development server:

To start Django Development server change into your outer directory and run the following command

$ python runserver

Now Go to http://localhost:8000/myapp/ in your browser,you will see the text which you defined in the index view.

“Hello,You’re at the myapp index.”