Press s to see the speaker notes.


Find the recording here.

Django
rixx

# rixx

🗺 rixx.de · 🐦 @rixxtr · 🐘 @rixx@chaos.social

Django
releases
Django

# manage.py

$ python ./manage.py help

Type 'manage.py help <subcommand>' for help on a specific subcommand.
Available subcommands:

[auth]
    changepassword
    createsuperuser
[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    …

# Datenbank

Postgres Mariadb MySQL SQLite Oracle

# Migrationen

$ python manage.py migrate

Operations to perform:
  Apply all migrations: auth, authtoken, contenttypes, myapp, sessions
Running migrations:
  No migrations to apply.
  Your models have changes that are not yet reflected in a migration, and so won't be applied.
  Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

# Dateien

media vs static

# Dateien

$ python ./manage.py collectstatic

You have requested to collect static files at the destination
location as specified in your settings:

    /home/myproject/src/myproject/src/static.dist

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes

496 static files copied to '/home/myproject/src/myproject/src/static.dist', 517 post-processed.

# Installation: Umgebung

  • Global
  • User environment / pip install --user
  • Virtualenv / python -m venv

# Installation: Nützliche Pfade

  • /usr/lib/python3.6/site-packages/
  • ~/.local/lib/python3.6/site-packages/
  • /path/to/venv/lib/python3.6/site-packages/

# Installation

  • pip install myproject
  • pip install .
  • pip install -r requirements.txt

# Konfiguration

  • local_settings.py
  • settings.py
  • something.cfg
  • ENV

# Konfigurationsvariablen

DEBUG = False
SECRET_KEY = 'skjdfölajfalskjfdsaölk…'
ALLOWED_HOSTS = ['example.org', '172.0.0.21']
DATABASES = {'default': {
  'ENGINE': 'django.db.backends.postgresql',
  'NAME': 'myproject',
  'USER': …
}}
STATIC_ROOT = '/var/www/project/static/'
MEDIA_ROOT = '/var/www/project/media/'

# Konfigurationsvariablen: Proxy

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_SSL_REDIRECT = False
USE_X_FORWARDED_HOST = True
USE_X_FORWARDED_PORT = True

# Bonus: Mail-Debugging

ADMINS = [
    ('Admin1', 'me@admin.org'),
    ('Admin2', 'me@example.org'),
]
EMAIL_HOST = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_HOST_USER = ''
EMAIL_PORT = 25
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
SERVER_EMAIL = 'sender@example.org'
LOGGING['handlers']['mail_admins'] = {
    'level': 'ERROR',
    'class': 'django.utils.log.AdminEmailHandler',
}

# Services

pip install gunicorn

[Unit]
Requires=myproject.socket
After=network.target

[Service]
User=myproject
WorkingDirectory=/home/myproject/src
ExecStart=/home/myproject/.local/bin/gunicorn --bind unix:/run/gunicorn/myproject --workers 4 myproject.wsgi
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

# Maintenance: Backups

  • Datenbank
  • Mediafiles
  • site-packages

# Maintenance: Updates

  • pip install (--user) -U …
  • python ./manage.py migrate
  • python ./manage.py collectstatic
  • python ./manage.py compress
  • python ./manage.py compilemessages

# Maintenance: Cronjobs

  • Manage commands
  • python ./manage.py clearsessions

# Ressourcen

Django Docs!

  • Supported versions
  • Security releases
  • Settings

Recording