Brief Notes
Noteworthy links, summaries and concise prose on stuff.

Django development

All about developing with Django.


To create a new Djangoproject named djangoproject: startproject djangoproject
cd djangoproject

To use an existing PostgreSQL database (for example, created earlier using CREATE DATABASE djangoproject;, change the DATABASES section in djangoproject/ to:

    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'djangoproject',
        'HOST': 'localhost',
        'PORT': '7777',

To set up initial database structure, in the Django project folder:

./ makemigrations
./ migrate
./ createsuperuser

To run the development server:

./ runserver

To serve static files such as CSS and images for all Django apps within a Django project in Production environment with uWSGI:

Step 1: Create a static folder on the same level as djangoapps/djangoproject/, say djangoapps/djangoproject/static. This folder will act as the collection point for all static files when djangoapps/djangoproject/ collectstatic is run later.

Step 2: Add the following lines in djangoapps/djangoproject/

STATIC_ROOT = "djangoapps/static" # Be sure to specify the full path

Step 3: Execute the following in the Django project folder:

./ collectstatic

Step 4: When starting uWSGI, specify the following option in the .ini file or on the commandline to let uWSGI correctly handle the serving of static files (see Serving static files with uWSGI (updated to 1.9) — uWSGI 2.0 documentation):

; uwsgi.ini file
static-map = /static=djangoapps/djangoproject/static  ; Be sure to specify the full path to the static folder

To create an additional app within a Django project:

./ startapp appname

Add appname to INSTALLED_APPS section inside djangoproject/