Link stylesheets to Django template

痞子三分冷 提交于 2019-12-05 17:37:28

The problem seemed to be that I needed the following code in my settings.py file:

STATICFILES_DIRS = (
    os.path.join(os.path.dirname(__file__), 'static').replace('\\','/'),
)

which is the same as the code to reference my templates folder. If you put the static files at the same level, it should work. This is also providing you have followed the advice of everyone on here, importing static etc.

  1. Make sure you have your static directory defined in your settings.py
  2. {% load staticfiles %}
  3. {% static 'css/mystyle.css' %} where you need the reference

For a start, you should have a leading slash:

href="/static/css/stylesheet.css" 

but really you should use the static tag:

{% load static %}
...
href="{% static 'css/stylesheet.css' %}"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!