django static file not loading

纵饮孤独 提交于 2019-12-05 20:07:28

The URL to the static-Files is "yourDomain/static/"

When you want to access to your "style.css" you should use "/static/style.css" instead of "/polls/style.css"

EDIT:

Change this part of your settings.py

STATICFILES_DIRS = (
    '/polls/static/'
    )

to

STATICFILES_DIRS = (
    'C:/django poll project/mysite/static'
    )

better would be:

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

Then the folder is called "static" and is on the same level where the "manage.py" is. When you put your style.css in this "static"-folder you can call it with "/static/style.css"

Updated Answer For Django 2.2 - 2019

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

BASE_DIR is already defined in settings.py

Also when loading, do {% load static %} instead of {% load staticfiles %}

It worked for me :

PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__))
STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, '..', 'static'),
)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!