Wiki

Home

Django

- [DJANGO FOR STARTUP FOUNDERS: A BETTER SOFTWARE ARCHITECTURE FOR SAAS STARTUPS AND CONSUMER APPS](https://alexkrupp.typepad.com/sensemaking/2021/06/django-for-startup-founders-a-better-software-architecture-for-saas-startups-and-consumer-apps.html)
- https://docs.timescale.com/timescaledb/latest/tutorials/monitor-django-with-prometheus/

Projekt Starten

- Djangoprojekt strukturieren:
  <https://docs.python-guide.org/writing/structure/#regarding-django-applications>
mkdir project
cd project
django-admin startproject mysite .

Development 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

- Models aktivieren
  
  <https://docs.djangoproject.com/en/2.1/intro/tutorial02/#activating-models>
- Models migrieren:
  
python manage.py makemigrations appname
python manage.py sqlmigrate polls 0001 # view the SQL code
python manape.py migrate

Misc

- Admin erstellen
  ```bash
  python manage.py createsuperuser
  ```
  
  <https://docs.djangoproject.com/en/2.1/intro/tutorial02/#make-the-poll-app-modifiable-in-the-admin>

Shell:

- <https://docs.djangoproject.com/en/2.1/intro/tutorial02/#playing-with-the-api>
        `python manage.py shell`
  <https://stackoverflow.com/questions/47170049/run-django-shell-in-ipython>
  
python manage.py shell -i ipython

Dotenv - Secret Management

- [Dotenv Module](https://pypi.org/project/python-dotenv/):
  ```bash
  pip install python-dotenv
  ```
- Generate a **SECRET_KEY**:
  ```bash
  python manage.py shell -c 'from django.core.management import utils; print(utils.get_random_secret_key())'
  ```
- Use the package `python-dotenv`.
  Create `.env` file:
  
  ```bash
  KEY=VALUE
  ```
  
  ```python
  import os
  from dotenv import load_dotenv
  
  # Load environment
  load_dotenv()
  
  KEY = os.getenv('KEY', 'default')
  KEY=os.environ['KEY']
  ```
-

Templating

Storage and S3