Skip to content Skip to sidebar Skip to footer

Static(css And Js) Files Are Not Working After Uploading Website On Heroku

I have just uploaded my website on heroku, the css and javascript files works perfectly on localhost but doesn't work after deploying. I also made sure to run this command python m

Solution 1:

Django does not serve static file on production and by default, Heroku does not support this, unless you add whitenoise to your project please follow these steps hopefully it will help you

You can follow the official documentation of Heroku for serving a static file on production.

Solution 2:

> Just replace your code with these lines

>urls.py

urlpatterns += static(settings.STATIC_URL,document_root=settings.STATICFILES_DIRS[0])

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

> settings.py
BASE_DIR = Path(__file__).resolve().parent.parent

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static")
]


MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

Make sure you run command using heroku cli: heroku run python manage.py collectstatic

Post a Comment for "Static(css And Js) Files Are Not Working After Uploading Website On Heroku"