Django Installation and usage synopsis:

To install Django, you can use pip which will come standard with Python versions 2.7.9 and 3.4+.  The version number is optional.

Install Django :  $sudo pip install django[==<version #>]

Check Version :  $django-admin --version

The django-admin startproject command will create a directory named after your project in the execution directory and populate it with various core project files.

Create a Project :  $django-admin startproject <project name>

Initial Project Folder contents :

Project management functions are performed using the file :

Django-admin and documentation

You will need an administrative user with which to login and manage your project using the Django web interface, this is done using :

There isn’t much to manage until you create some content, so we will revisit the administrator login later.  Django projects consist of Django applications.  An app will contain data models, templates, views, and other files which will define its functionality and appearance.  From the main project folder :  python startapp sample_application .  This will create a new folder with the following initial contents :

Every application must be registered in the project’s file, which is contained in the project subfolder :

Django documentation – you should get familiar with these settings, keep in mind the values in this file should not be altered at runtime, treat these as constants defined in

Databases are created and managed using Models, which are essentially classes containing the various field definitions.  These are contained in and defined as in the example below :

Models documentation

When changes are made to, they must be migrated in order to be applied to the database structure.  When a project is initially created, a first migration must be run to create the core database structures.  Migrations are made using the makemigrations parameter; run from the main project folder :

This adds the model information to the  project_folder/sample_application/migrations/ directory, in the form of a model file.  These changes must subsequently be applied.  A list of all migrations can be viewed as follows :

The brackets will be filled with an X when the migrations have been applied.  Apply them using‘s migrate parameter :

Here we can see a database was initialized in the file db.sqlite3 and, when listed, the migrations are marked as applied.  Models must also be registered in the app’s file to allow modification via web login as the site administrator.  To register your model, edit the app’s file :

Each individual model class would need to be registered in the application’s, which makes it available to the application and administrative portal.  The example above will cause issues if the item is already registered, there is a helpful function decorator which can assist with registering your models.  The example below uses the django.contrib.admin.register decorator to register the model in question when invoking the …admin.ModelAdmin child class :

If the model has not been registered in one of the methods described, errors will be raised in the makemodel routine.  The  /admin/ site is highly customizable, as always the documentation is very helpful.

Bring up the wsgi server  :

Now the administrative login portal should be up and available using the URL (http://localhost:8000/admin/).  Logging in presents you with a dashboard and a few options.



Once logged in, you are able to add database entries, and manage other aspects of the project.

At this point, your project is ready for content.   Django applications deliver web content in the form of views, which are managed in an app’s file.  Views will use HTML templates and static resources to build the actual web pages that will be presented by the server.  [Templates, apache mod_wysgi, proxy setups, and Static content requirements to come]