Handle media files properly (best practice)
Unlike static files, media files need to be properly persisted. Ideally, on an external file system that is being backup'ed and can be restored independently from the Django application.
Unsuitable default settings
Most importantly, a directory location relative to the Django settings file (derived from BASE_DIR
) most likely doesn't make sense when you prepare and deploy your Django project as a Python package, like we do.
Django's default settings make the two folders be placed inside the Python site-packages folder, which could be problematic, e.g.
$ pip install django-example
...
Successfully installed asgiref-3.6.0 django-4.2.1 django-environ-0.10.0 django-example-0.1.0 gunicorn-20.1.0 psycopg2-2.9.6 sqlparse-0.4.4 whitenoise-6.4.0
$ manage.py collectstatic --noinput --link
125 static files symlinked to '/usr/local/lib/python3.10/site-packages/static'.
Related
- Using pyproject.toml in your (Django) project (Peter Baumgartner)
- Prepping Your Project for Production by Peter Baumgartner (DjangoCon 2019, YouTube)
Edited by Peter Bittner