From c3e0fb250f0bf847303b3536ea8a508a80b7e590 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Mon, 9 Nov 2020 16:04:36 +0100 Subject: [PATCH] added whitenoise to serve static files --- README.md | 13 ++++++++++++- foerderbarometer/settings.py | 8 ++++---- foerderbarometer/settings_development.py | 6 +++--- foerderbarometer/settings_production.py | 7 ++++--- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ec83599..f39f49f 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,20 @@ purpose: gather data from intern(WMDE) and extern(volunteers) forms to create a python 3.8.2 django 3.1.1 django-formtools 2.2 + whitenoise 5.2.0 ## production setup cp foerderbarometer/settings_production.py foerderbarometer/settings.py -edit /secrets.json +edit /secrets.json to contain something similar to + +{ + "DATABASE_PASSWORD": "THIS IS TOP SECRET!" +} + + python manage.py collectstatic + +add to cron one time a day: + + python manage.py sendmails diff --git a/foerderbarometer/settings.py b/foerderbarometer/settings.py index 3f40d9b..c0568a6 100644 --- a/foerderbarometer/settings.py +++ b/foerderbarometer/settings.py @@ -44,7 +44,9 @@ def get_secret(setting, secrets=secrets): SECRET_KEY = '*&7p9#_n$@^%0z49s+7jpy@+j1rw_hqh05knyd6y2*!0)r&b6h' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False + +STATIC_ROOT = BASE_DIR / 'staticfiles' ALLOWED_HOSTS = ['*'] @@ -59,14 +61,12 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - # 'django.contrib.sites', 'formtools', ] -# SITE_ID = 1 # needed for contrib.sites - MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', diff --git a/foerderbarometer/settings_development.py b/foerderbarometer/settings_development.py index 3f40d9b..f3708a8 100644 --- a/foerderbarometer/settings_development.py +++ b/foerderbarometer/settings_development.py @@ -46,6 +46,8 @@ SECRET_KEY = '*&7p9#_n$@^%0z49s+7jpy@+j1rw_hqh05knyd6y2*!0)r&b6h' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True +STATIC_ROOT = BASE_DIR / 'staticfiles' + ALLOWED_HOSTS = ['*'] @@ -59,14 +61,12 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - # 'django.contrib.sites', 'formtools', ] -# SITE_ID = 1 # needed for contrib.sites - MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', diff --git a/foerderbarometer/settings_production.py b/foerderbarometer/settings_production.py index 709c201..9a650dd 100644 --- a/foerderbarometer/settings_production.py +++ b/foerderbarometer/settings_production.py @@ -48,7 +48,9 @@ def get_secret(setting, secrets=secrets): SECRET_KEY = '*&7p9#_n$@^%0z49s+7jpy@+j1rw_hqh05knyd6y2*!0)r&b6h' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False + +STATIC_ROOT = BASE_DIR / 'staticfiles' ALLOWED_HOSTS = ['*'] @@ -63,14 +65,13 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - # 'django.contrib.sites', 'formtools', ] -# SITE_ID = 1 # needed for contrib.sites MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',