Django

DRY model-view-controller framework for Python web applications.
web | code | documentation | awesome | BSD

See also | :python
See also (alternative) | :ruby (Rails)

Notes

Tutorials

https://djangogirls.org/resources/ (complete project)
https://code.djangoproject.com/wiki/Tutorials
https://rnevius.github.io/django_request_response_cycle.png

Ubuntu setup

https://wiki.ubuntu.com/Django
https://help.ubuntu.com/community/Django

Nginx + Postgres + Ubuntu setup

System

  1. Install :nginx
  2. Install :postgresql (could be on a separate machine)
    1. With a user for django (with CREATE DATABASE privileges)
    2. With psycopg2 dependencies
  3. Install :python
    1. With python-dev (for :uwsgi)

Site

  1. Create empty database (with/for django user)
  2. Create and activate virtualenv
  3. pip install Django
  4. pip install uwsgi
  5. pip install psycopg2
  6. Go to parent of code folders
  7. django-admin startproject <site name>

Connections

  1. Connect to database in settings.py
    1. See https://docs.djangoproject.com/en/1.9/intro/tutorial02/
    2. See https://docs.djangoproject.com/en/1.9/ref/settings/#databases
  2. Start Django as a Unix socket via uwsgi
    1. https://uwsgi.readthedocs.org/en/latest/tutorials/Django_and_nginx.html
    2. https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/uwsgi/
  3. Connect Nginx to the socket
    1. Probably need to chown-socket = www-data:www-data

Other references

Hosting at a subpath (via Nginx)

Modify the Nginx location block as follows:

location /subpath { # rather than / (aka root)
	....
	wsgi_param SCRIPT_NAME /subpath; # explicitly set SCRIPT_NAME to match subpath
	uwsgi_modifier1 30; # strips SCRIPT_NAME from PATH_INFO (the url passed to Django)
	....
}

See http://stackoverflow.com/a/36572641/236081

Administration interface

Customization
https://docs.djangoproject.com/en/1.9/intro/tutorial07/#customize-the-admin-form
https://docs.djangoproject.com/en/1.9/ref/contrib/admin/actions/ (custom actions from admin interface)

Summary row
http://dfrdmn.com/post/55104336478/adding-summary-row-in-django-admin

CSV/spreadsheet export
https://github.com/LibraryOfCongress/django-tabular-export

Deployment

Model updates

References:
https://docs.djangoproject.com/en/1.9/intro/tutorial02/#activating-models
https://docs.djangoproject.com/en/1.9/ref/django-admin/

Packaging

ERD diagrams

https://github.com/LegoStormtroopr/django-spaghetti-and-meatballs
https://django-spaghetti-and-meatballs.readthedocs.io/en/stable/

Kinda related to :graph-drawing



Backlinks: stack python slack ruby graph-drawing django:authentication

CC0 / Public domain dedication To the extent possible under law, d3vid seaward has waived all copyright and related or neighboring rights to "Django in Grasmere notebook, including code snippets" (why? how?)