python - 如何修复styles.css:1 加载资源失败:服务器响应状态为404?
问题描述
我正在尝试学习 django 并且我的 css 文件无法与 html 文件 idk 链接为什么
这是静态文件夹的树:
├── images
├── js
├── plugins
└── styles
└── styles.css
设置.py
STATIC_URL = '/static/'
STATICFILES_DIR = [
os.path.join(BASE_DIR, 'static')
]
索引.html
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Register</title>
{% load static %}
<link rel="stylesheet" href="{% static './styles/styles.css' %}">
</head>
<!-- <script src="../data/script-clac.js" type="text/javascript"></script> -->
<body class="body1">
<div class="div1">
<h2>Register</h2>
<p class="text">Name</p>
<input type="text" placeholder="Enter your name" id="name">
<p class="text">Username</p>
<input type="text" placeholder="Choose a username" id="username">
<p class="text">Password</p>
<input type="password" placeholder="Choose a password" id="password">
<p id="result"></p>
<input type="checkbox" onclick="myFunction()">Show Password
<button id="btn">Calculate</button>
</div>
</body>
</html>
错误信息:
styles.css:1 加载资源失败:服务器响应状态为 404(未找到)
很久以来我一直在尝试解决这个问题,请帮助我。
另外,这是我的项目目录
解决方案
在设置文件中添加STATICFILES_DIRS
前任:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
推荐阅读
- python - 将列表转换为字典时键被打乱
- javascript - 如何创建枚举元素句柄
- flutter - 如何将颤振添加到android studio?
- reactjs - 在引用数据类型上调用 .get() 后未呈现 Firestore 数据
- flutter - TextFormField 中的水平滚动在文本输入时颤动
- macos - 登录屏幕密码在 MacOS bigsur 中不起作用。如何解决?
- javascript - Div 不使用鼠标滚轮滚动,但滚动条可以?
- uml-designer - 在 UML Designer 中旋转元素
- javascript - 如何在网站上使用机密生产密钥?
- json - 在颤振中没有得到适当的 api 共鸣