css - 链接到有效的外部 css,但显示未设置样式
问题描述
我的项目论坛将其文件构建为:
forum
├── __init__.py
├── settings.py
├── static
│ └── css
│ └── bootstrap.min.css
├── templates
│ └── index.html
├── urls.py
└── wsgi.py
我将“bootstrap.min.css”链接到index.html
喜欢:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Forum Home Page</title>
<link rel="stylesheet" href="/static/css/bootstrap.min.css" />
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-12">
<h2>Coding Journey</h2>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-md-2">Concepts
<button type="button" class="btn btn-success">Submit</button>
</div>
<div class="col-xs-12 col-md-2">Reading</div>
<div class="col-xs-12 col-md-2">Coding</div>
</div>
</div> <!--container-->
</body>
</html>
但是,当index.html
在浏览器中打开时,它根本没有样式。
我的操作有什么问题?
设置.py
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static")
)
解决方案
查看您的设置文件,这可能是因为您仅将一个字符串作为字符串列表/元组传递....
我认为您的意思是
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"), # notice the comma here
)
这是 Python 的问题之一,您需要添加显式逗号来区分元组和括号
推荐阅读
- android - Error inflating class androidx.constraintlayout.widget.ConstraintLayout in Android 4
- css - How to change background color of active Navigation Tab?
- reactjs - observable catchError after request failure (axios/redux)
- batch-file - Unknown "missing operand" comment in Batch program
- r - 关于使用 M3C 包进行主成分分析
- php - 当我将数据导出到 Excel 时,类 DateTime 错误的对象
- php - Laravel 颤振登录
- spring - 在不同的项目中共享 application.properties 文件
- python - 如何将控制台发送到手机的验证码放到一个pyqt5小部件中?
- javascript - 使用 Promise.all 嵌套 async/await