Categories
Python Answers

How to fix 404 error with accessing static files with Python Django?

Spread the love

Sometimes, we want to fix 404 error with accessing static files with Python Django.

In this article, we’ll look at how to fix 404 error with accessing static files with Python Django.

How to fix 404 error with accessing static files with Python Django?

To fix 404 error with accessing static files with Python Django, we can add our static file folder to STATICFILES_DIRS in settings.py.

For instance, we write

import os.path

STATIC_ROOT = ''

STATIC_URL = '/static/'

STATICFILES_DIRS = ( os.path.join('static'), )

to set STATICFILES_DIRS to a tuple with the static file path in our project.

Conclusion

To fix 404 error with accessing static files with Python Django, we can add our static file folder to STATICFILES_DIRS in settings.py.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

One reply on “How to fix 404 error with accessing static files with Python Django?”

Leave a Reply

Your email address will not be published. Required fields are marked *