Django cannot find my static files

Viewed 10303

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 run the server:

Not Found: /users/login/js/bootstrap.min.js for example.

I have {% load staticfiles %} at the top of my html and in my settings.py I have:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 
STATIC_URL = '/static/'                                                                                        
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Thanks.


EDIT: Fixed with a combination of the answers below. Thank you all!

4 Answers

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

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

Related