· 7 years ago · Feb 12, 2018, 03:58 PM
1"""
2Django settings for {{ project_name }} project on Heroku. For more info, see:
3https://github.com/heroku/heroku-django-template
4For more information on this file, see
5https://docs.djangoproject.com/en/2.0/topics/settings/
6For the full list of settings and their values, see
7https://docs.djangoproject.com/en/2.0/ref/settings/
8"""
9
10import os
11import dj_database_url
12
13# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
14BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
15PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
16
17
18# Quick-start development settings - unsuitable for production
19# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/
20
21# SECURITY WARNING: keep the secret key used in production secret!
22SECRET_KEY = "{{ secret_key }}"
23
24# SECURITY WARNING: don't run with debug turned on in production!
25DEBUG = True
26
27# Application definition
28
29INSTALLED_APPS = [
30 'django.contrib.admin',
31 'django.contrib.auth',
32 'django.contrib.contenttypes',
33 'django.contrib.sessions',
34 'django.contrib.messages',
35 # Disable Django's own staticfiles handling in favour of WhiteNoise, for
36 # greater consistency between gunicorn and `./manage.py runserver`. See:
37 # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
38 'whitenoise.runserver_nostatic',
39 'django.contrib.staticfiles',
40]
41
42MIDDLEWARE = [
43 'django.middleware.security.SecurityMiddleware',
44 'whitenoise.middleware.WhiteNoiseMiddleware',
45 'django.contrib.sessions.middleware.SessionMiddleware',
46 'django.middleware.common.CommonMiddleware',
47 'django.middleware.csrf.CsrfViewMiddleware',
48 'django.contrib.auth.middleware.AuthenticationMiddleware',
49 'django.contrib.messages.middleware.MessageMiddleware',
50 'django.middleware.clickjacking.XFrameOptionsMiddleware',
51]
52
53ROOT_URLCONF = '{{ project_name }}.urls'
54
55TEMPLATES = [
56 {
57 'BACKEND': 'django.template.backends.django.DjangoTemplates',
58 'DIRS': [],
59 'APP_DIRS': True,
60 'OPTIONS': {
61 'context_processors': [
62 'django.template.context_processors.debug',
63 'django.template.context_processors.request',
64 'django.contrib.auth.context_processors.auth',
65 'django.contrib.messages.context_processors.messages',
66 ],
67 'debug': DEBUG,
68 },
69 },
70]
71
72WSGI_APPLICATION = '{{ project_name }}.wsgi.application'
73
74
75# Database
76# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
77
78DATABASES = {
79 'default': {
80 'ENGINE': 'django.db.backends.sqlite3',
81 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
82 }
83}
84
85AUTH_PASSWORD_VALIDATORS = [
86 {
87 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
88 },
89 {
90 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
91 },
92 {
93 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
94 },
95 {
96 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
97 },
98]
99
100# Internationalization
101# https://docs.djangoproject.com/en/2.0/topics/i18n/
102
103LANGUAGE_CODE = 'en-us'
104TIME_ZONE = 'UTC'
105USE_I18N = True
106USE_L10N = True
107USE_TZ = True
108
109# Change 'default' database configuration with $DATABASE_URL.
110DATABASES['default'].update(dj_database_url.config(conn_max_age=500))
111
112# Honor the 'X-Forwarded-Proto' header for request.is_secure()
113SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
114
115# Allow all host headers
116ALLOWED_HOSTS = ['*']
117
118# Static files (CSS, JavaScript, Images)
119# https://docs.djangoproject.com/en/2.0/howto/static-files/
120
121STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
122STATIC_URL = '/static/'
123
124# Extra places for collectstatic to find static files.
125STATICFILES_DIRS = [
126 os.path.join(PROJECT_ROOT, 'static'),
127]
128
129# Simplified static file serving.
130# https://warehouse.python.org/project/whitenoise/
131STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'