Django

Python

Projekt Starten

Djangoprojekt strukturieren: https://docs.python-guide.org/writing/structure/#regarding-django-applications

mkdir project
cd project
django-admin startproject mysite .

Run the internal server:

python manage.py runserver

Die Webseite sollte hier verfuegbar sein: http://127.0.0.1:8000/

Docker Projekt Template

https://gitlab.com/rayendumeldust/django-docker-template

Neue App erstellen

python manage.py startapp appname

Models/DB

https://docs.djangoproject.com/en/2.1/intro/tutorial02/#activating-models

python manage.py makemigrations appname
python manage.py sqlmigrate polls 0001 # view the SQL code
python manape.py migrate

Misc

https://docs.djangoproject.com/en/2.1/intro/tutorial02/#make-the-poll-app-modifiable-in-the-admin

https://stackoverflow.com/questions/47170049/run-django-shell-in-ipython

python manage.py shell -i ipython

Secret Management

Create .env file:

KEY=VALUE
from dotenv import load_dotenv

# Load environment
load_dotenv()

KEY = os.getenv('KEY')

Templating

Storage and S3