我的项目论坛将其文件构造为:

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时,根本没有设置样式。

我的操作有什么问题?

css - 链接到有效的外部CSS,但显示样式未设置-LMLPHP

setting.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的问题之一,您需要添加一个显式逗号来区分元组和正括号

关于css - 链接到有效的外部CSS,但显示样式未设置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50479321/

10-10 14:11
查看更多