[英]Django web app "Not allowed to load local resource /.css file"
I cant load css file in my web page it just gives me a simple page without css elements as shown in the screenshot and says it cant load local resource Page and inspect elememt I've loaded the static files in settings我无法在我的网页中加载 css 文件它只是给了我一个没有 css 元素的简单页面,如屏幕截图所示,并说它无法加载本地资源页面并检查元素我已经在设置中加载了静态文件
STATIC_URL = '/static/'
STATICFILES_DIRS=[
os.path.join(BASE_DIR,'assets')
]
STATIC_ROOT=os.path.join(BASE_DIR,'assets')
added url添加网址
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
used this in html在 html 中使用这个
{%load static%}
<head>
<meta charset="UTF-8">
<title>LOGIN</title>
<link rel="stylesheet" href="{% static 'assets/styles/style.css' %}">
</head>
also did manage.py collectstatic也做了 manage.py collectstatic
followed the docs dont know where i went wrong按照文档不知道我哪里出错了
You should use a link
tag:您应该使用
link
标签:
<link rel="stylesheet" href="{% static 'assets/styles/style.css' %}">
That is enough to load the file;这足以加载文件; so you don't need the following:
所以你不需要以下内容:
{% include "assets/styles/style.css" %}
and also, you should change your settings like below if your css file is in BASE_DIR/assets/style.css
:而且,如果您的 css 文件在
BASE_DIR/assets/style.css
,您应该像下面一样更改您的设置:
STATICFILES_DIRS=[
os.path.join(BASE_DIR,'assets')
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.