i have problem with static files in production , when DEBUG is False (i already deployed my Django project in Heroku )
Make sure your settings file has the STATIC_URL AND STATIC_ROOT set properly and update allowed hosts, also be sure to run python manage.py collectstatic to generate the static files and you may need to install whitenoise middleware. Lastly be sure to use the {% load static %} directive in your templates.
i did smth like this
Static files (CSS, JavaScript, Images)
How to manage static files (e.g. images, JavaScript, CSS) | Django documentation | Django
STATIC_URL = âstatic/â
STATIC_ROOT = os.path.join(BASE_DIR, âstaticâ)
MEDIA_ROOT = BASE_DIR / âuploads/â
MEDIA_URL = âmedia/â
STATICFILES_STORAGE = âwhitenoise.storage.CompressedManifestStaticFilesStorageâ
also this :
MIDDLEWARE = [
âdjango.middleware.security.SecurityMiddlewareâ,
âwhitenoise.middleware.WhiteNoiseMiddlewareâ,
âdjango.contrib.sessions.middleware.SessionMiddlewareâ,
When encountering issues with static files in a Django project deployed on Heroku with DEBUG
set to False
, itâs crucial to ensure that your static files are collected into the designated STATIC_ROOT
directory using the collectstatic
command. Double-check your Django projectâs static file configurations, including STATIC_URL
and STATIC_ROOT
, and make sure Whitenoise is correctly configured for efficient static file serving. Verify that your HTML templates reference static files using the {% static %}
template tag, and consider Heroku-specific settings for static file handling. Additionally, inspect HTTP headers, check logs for error messages, and re-deploy your project after making any changes to configurations for a seamless static file serving experience in your production environment.