Static files error!

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.

1 Like