Skip to content Skip to sidebar Skip to footer

Django Cannot Find My Static Files

I am relatively new to web dev. and I am trying to build my first web application. I have my static folder in project_root/static but for some reason, I keep getting 404s when I ru

Solution 1:

put your static js, css and other files in a directory called static inside your project directory then these settings will work:

# this defines the url for static files# eg: base-url.com/static/your-js-file.js
STATIC_URL = '/static/'# this is directory name where collectstatic files command will put your app level static files
STATIC_ROOT = 'staticfiles'# this is directory paths where you have to put your project level static files# you can put multiple folders here
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

based on these settings you will be able to access your static files correctly

Solution 2:

Go ahead and read this- http://agiliq.com/blog/2013/03/serving-static-files-in-django/

Summary: If "users" is the app name in your project, then create directory - 'users/static/js/'. and put bootstrap.min.js into js/. This file will be accessible at localhost:8000/static/js/bootstrap.min.js. Go ahead and try it out.

Solution 3:

If DEBUG=True is settings.py it won't work. In such cases Django expects Apache/Nginx to take care of static files.

Solution 4:

Use below code in settings.py

MEDIA_URL = '/media/'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_ROOT = '/xxx/site/public/static/'
MEDIA_ROOT =  '/xxx/site/public/media/'

or Delete or comment DEBUG = True in settings.py

Post a Comment for "Django Cannot Find My Static Files"