Menu Close

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

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.

Posted in Python, Python Answers