Tutorial by Examples

You can set the timezone that will be used by Django in the settings.py file. Examples: TIME_ZONE = 'UTC' # use this, whenever possible TIME_ZONE = 'Europe/Berlin' TIME_ZONE = 'Etc/GMT+1' Here is the list of valid timezones When running in a Windows environment this must be set to the same a...
Once you've got all your settings, you'll want to use them in your code. To do so, add the following import to your file: from django.conf import settings You may then access your settings as attributes of the settings module, for example: if not settings.DEBUG: email_user(user, message) ...
It's a bad idea to hard code paths in your application. One should always use relative urls so that your code can work seamlessly across different machines. The best way to set this up is to define a variable like this import os BASE_DIR = os.path.dirname(os.path.dirname(__file__)) Then use th...
Using environment variables is a widely used way to setting an app's config depending on it environment, as stated in The Twelve-Factor App. As configurations are likely to change between deployment environments, this is a very interesting way to modify the configuration without having to dig in th...
Django default project layout creates a single settings.py. This is often useful to split it like this: myprojectroot/ myproject/ __init__.py settings/ __init__.py base.py dev.py prod.py tests.py This enables...
Each requirements files should match the name of a settings files. Read Using multiple settings for more information. Structure djangoproject ├── config │ ├── __init__.py │ ├── requirements │ │ ├── base.txt │ │ ├── dev.txt │ │ ├── test.txt │ │ └── prod.txt │ └── setti...
When using a VCS such as Git or SVN, there are some secret data that must never be versioned (whether the repository is public or private). Among those data, you find the SECRET_KEY setting and the database password. A common practice to hide these settings from version control is to create a file...
In PaaS sites such as Heroku, it is usual to receive the database information as a single URL environment variable, instead of several parameters (host, port, user, password...). There is a module, dj_database_url which automatically extracts the DATABASE_URL environment variable to a Python dictio...

Page 1 of 1