From f9cb44c66b7b3afb4c8c6962385e3ecbd90be206 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Wed, 3 Jun 2020 19:58:01 +0200 Subject: [PATCH] gunicorn media file serving --- .env.template | 4 ++++ .idea/dictionaries/vabene1111_PC.xml | 7 +++++++ recipes/settings.py | 2 ++ recipes/urls.py | 2 +- 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .idea/dictionaries/vabene1111_PC.xml diff --git a/.env.template b/.env.template index b6a3ef1a5..d1a10f582 100644 --- a/.env.template +++ b/.env.template @@ -7,6 +7,10 @@ ALLOWED_HOSTS=* # random secret key, use for example base64 /dev/urandom | head -c50 to generate one SECRET_KEY= +# serve mediafiles directly using gunicorn, technically not a "best practice" but for the expected small deployments +# of this application absolutely sufficient. If False some kind of webserver (for example nginx) is needed to server mediafiles +GUNICORN_MEDIA=True + # add only a database password if you want to run with the default postgres, otherwise change settings accordingly DB_ENGINE=django.db.backends.postgresql_psycopg2 POSTGRES_HOST=db_recipes diff --git a/.idea/dictionaries/vabene1111_PC.xml b/.idea/dictionaries/vabene1111_PC.xml new file mode 100644 index 000000000..653189d8d --- /dev/null +++ b/.idea/dictionaries/vabene1111_PC.xml @@ -0,0 +1,7 @@ + + + + gunicorn + + + \ No newline at end of file diff --git a/recipes/settings.py b/recipes/settings.py index f87b1a552..eddeada0b 100644 --- a/recipes/settings.py +++ b/recipes/settings.py @@ -21,6 +21,8 @@ SECRET_KEY = os.getenv('SECRET_KEY') if os.getenv('SECRET_KEY') else '728f4t5438 DEBUG = bool(int(os.getenv('DEBUG', True))) +GUNICORN_MEDIA = bool(int(os.getenv('GUNICORN_MEDIA', True))) + ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS').split(',') if os.getenv('ALLOWED_HOSTS') else ['*'] LOGIN_REDIRECT_URL = "index" diff --git a/recipes/urls.py b/recipes/urls.py index 0a66c1238..8d2d7f59e 100644 --- a/recipes/urls.py +++ b/recipes/urls.py @@ -25,5 +25,5 @@ urlpatterns = [ path('i18n/', include('django.conf.urls.i18n')), ] -if settings.DEBUG: +if settings.GUNICORN_MEDIA or settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)