我得到以下错误强>
GEThttp://127.0.0.1:8000/static/bootstrap/css/bootstrap.min.cssnet::ERR_中止404(未找到) GEThttp://127.0.0.1:8000/static/bootstrap/css/bootstrap-grid.min.cssnet::ERR_中止404(未找到) GEThttp://127.0.0.1:8000/static/bootstrap/css/bootstrap-reboot.min.cssnet::ERR_中止404(未找到) . . . 等等
settings.py中的URL设置如下:强>
STATIC_URL = '/static/'
STATICFILES_DIR = [
os.path.join(BASE_DIR, 'static'),
]
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
我已经在模板中输入了静态文件URL(home.html)强>
{%load static%}
<!DOCTYPE html>
<html >
<head>
<!-- meta data -->
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
<link rel="shortcut icon" href="{% static 'images/logo4.png' %}" type="image/x-icon">
<meta name="description" content="Website Builder Description">
<title>home.html</title>
<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap-grid.min.css' %}">
<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap-reboot.min.css' %}">
<link rel="stylesheet" href="{% static 'tether/tether.min.css' %}">
<link rel="stylesheet" href="{% static 'dropdown/css/style.css' %}">
<link rel="stylesheet" href="{% static 'animatecss/animate.min.css' %}">
<link rel="stylesheet" href="{% static 'theme/css/style.css' %}">
我的文件夹结构如下:
有人能帮我解决这个问题吗
多谢各位
在settings.py中,调试设置为TRUE
我把所有的静态文件都放在“static”文件夹中(我已经验证了static filder中的文件路径,按顺序排列),所以Django应该找到静态文件
下面是my templates/home.html的完整代码
有关加载的代码和网页,请参阅以下屏幕截图:
您设置:
这意味着,django将在资产中找到静态文件,如png、jpg、css、js
但你也设定了:
这意味着,django还将在静态中找到静态文件,如果在资产中找不到文件
因此,如果您确定静态文件位于其中一个文件夹中,您可以检查以下设置:
如果将调试设置为
False
,django的应用服务器将不会提供静态文件APIDjango document告诉您如何部署静态文件,使用nginx,uwsgi就可以了
另外,您可以使用
serve
在url.py中获取它(在django.views.static中不建议使用这种方式)如果您确定,两个静态文件都在正确的文件夹中,并将
DEBUG
设置为True
,可能是由于其他错误,请显示更多代码STATICFILES\u DIR不正确,它是STATICFILES\u DIRS(DIR结尾带有一个S,因此它必须是复数)
https://docs.djangoproject.com/en/3.1/ref/settings/#std:setting-STATICFILES_DIRS
相关问题 更多 >
编程相关推荐