gunicorn media file serving

This commit is contained in:
vabene1111 2020-06-03 19:58:01 +02:00
parent d09c6dbfed
commit f9cb44c66b
4 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -0,0 +1,7 @@
<component name="ProjectDictionaryState">
<dictionary name="vabene1111-PC">
<words>
<w>gunicorn</w>
</words>
</dictionary>
</component>

View File

@ -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"

View File

@ -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)