3. Django¶
3.1. Setup virtual environments¶
cd mysite
python3 -m venv venv
venv/bin/active
source myvenv/bin/activate
pip install django
3.2. Create new project¶
django-admin startproject mysite
3.3. Useful¶
3.3.1. Internationalization¶
https://docs.djangoproject.com/en/2.0/topics/i18n/translation/
python manage.py makemessages -l de
python manage.py compilemessages -l de
3.3.2. python-decouple¶
Use the decouple package for saving secret settings.
install:
pip install python-decouple
in your settings.py:
from decouple import config
SECRET_KEY = config('SECRET_KEY')
create file .env with:
SECRET_KEY=value
3.3.3. dj-database-url¶
The dj-database-url help to configuret the db-settings in one line.
install:
pip install dj-database-url
in your settings.py:
import dj_database_url
DATABASES = {
'default': dj_database_url.config(
default='sqlite:///db.sqlite3'
)
}
3.4. Manage the project¶
python manage.py startapp
python manage.py makemigrations
python manage.py migrate
python manage.py test
python manage.py createsuperuser
python manage.py collectstatic
3.5. Structure¶
mysite
├── myapp
│ ├── migrations
│ │ └── __init__.py
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── mysite
│ ├── settings
│ │ ├── __init__.py
│ │ ├── base.py
│ │ └── development.py
│ ├── __init__.py
│ ├── urls.py
│ ├── wsgi.py
│ └── uwsgi.ini
├── manage.py
├── server.py
├── README.md
└── requirements.txt