我无法对我的静态目录进行排序,并通过django的html页面中的模板链接css文件。我一直收到错误" Not Found:/CSS/bootstrap.min.css"
我知道这是我在settings.py中设置目录的问题,但我似乎无法解决问题。下面是我的settings.py和layout.html的代码(页面i' m使用调用css文件)。
的layout.html
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Testing {% block title %}{% endblock %}</title>
<link href="{% static 'css/bootstrap.min.css' %}" type="text/css" rel="stylesheet">
</head>
<body>
<div class="container">
{% block content %}
{% endblock %}
</div>
</body>
</html>
settings.py
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL = 'C:/Users/Luke/Desktop/Capstone/CapstoneNotespool/capstonenotespool/capstonenotespool/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
答案 0 :(得分:0)
你快到了!您只需要将正确的静态文件目录添加到STATICFILES_DIRS。
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# STATIC_URL tells django the url path to use for all static files. It
# doesn't really have anything to do with your file locations on your
# computer.
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
# Add this line here.
os.path.join(BASE_DIR, "capstonenotespool", "static"),
]
答案 1 :(得分:0)
我认为你必须再次检查你的静态网址,我认为你配置错了。
这是你要找的答案。
这是我的配置
STATIC_URL =&#39; / static /&#39;
如果DEBUG:
MEDIA_URL =&#39; / media /&#39;
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR),&#34; static&#34;,&gt;&#34; static-only&#34;)
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR),&#34;静态&#34;,&gt;&#34;媒体&#34;)
STATICFILES_DIRS =( os.path.join(os.path.dirname(BASE_DIR),&#34; static&#34;,&#34; static&#34;),
)