while working in the Development environment we use
python manage.py runserver so Django makes the development environment faster automatically by serving the static files for us.
python manage.py runserver command uses
django.contrib.staticfiles module to server the static files in development when DEBUG is set to True. if we set DEBUG to False then it does not uses
django.contrib.staticfiles. and then we have to server our static files manually by
from django.conf import settings from django.conf.urls.static import static urlpatterns = [ # ... the rest of your URLconf goes here ... ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
as described in the Docs
In Production Django just dont want to serve static files for us its just neglect all of them.. so for that we have light weight library, which can easily solve this problem, Called whitenoise.
solve your problem in three steps:-
pip install whitenoise.
"whitenoise.middleware.WhiteNoiseMiddleware",add this middleware to your
"whitenoise.runserver_nostatic",add this line to your I
This is how i handled my static files in production as like so many other guys. Hope you can too!