Css and Js files are giving 404 error

I have set up the program and confirm that white noise library is also installed. so I fire up the application after collecting the static files.

The static files of the admin is getting collected but the other static files like materilize.css and materlize.js is not there in the stati root.

While I am checking the server response I found its throwing 404 error

Could you please help me in letting know how I can correct it

Please note that in helloworld application its working fine

Hi @asainiabhishek07
Setting up static files can be tricky in Django. There are a few points to note

  1. Django doesn’t support serving static files. That means when you change DEBUG to false in settings.py file django won’t serve static files for you
  2. Out of the box there is no settings for serving static files even in development mode

Solution:

  1. Using Django’s internal support for serving static files in Development mode:
  2. Make sure you have django.contrib.staticfiles in you INSTALLED_APPS
  3. Add a STATIC_URL in you settings.py file
  4. Add a STATICFILES_DIRS in you settings.py file which will be a list of all the directories where your static files live
  5. Restart the server and done !
  6. Use 3rd party libraries to serve static files. In Django - Portfolio Project 1 video you can skip to 8:55 and there you’ll find the way to setup whitenoise to serve your static files.

Hope this might helps :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.