Bootstrap链接不正确



我的网站未正确设置bootstrap设计。我在index.html,

中写道
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/static/index.css">
    <link rel="stylesheet" href="/static/bootflat/css/bootflat.min.css">
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <script src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
  </head>
      ・
    ・

在设置中。py

import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR,'bootflat.github.io'), ]

当我单击href ="/static/css/bootstrap.min.css"时,发生404错误。目录结构就像

-PythonServer
  -PythonServer
  -logic
   -static
    -index.css
   -templates
    -index.html
  -boolflat.github.io
  -bower_components

我认为我正确设置了static_url,所以我不知道为什么没有设置bootstrap设计。我的代码中有什么错误?我应该如何解决此问题?

base.html:

{% load staticfiles %}
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

...您的CSS ...

{% block head %}
{% endblock head %}

请注意订单很重要,您需要首先添加引导程序,然后您的CSS为您所有的CSS都可以正常工作。

用于在项目中添加静态文件,该过程为

  • 创建一个新的目录,称为static在您的项目文件夹中
  • 在该目录中,您可以添加图像文件夹或任何静态内容。
  • 您还必须将此目录路径添加到Project的设置。
  • 为了将其添加到HTML文件中,您将需要标记模板,即{% load staticfiles %}。此行将追随HTML声明之后,这将使您的静态内容加载到您的HTML文件中。
  • 在您的SRC或HREF属性中使用模板标记总是好的对于ex - <img src={% static 'images/img.png' %}

因此,根据您的代码,要包括两个要点,首先是添加任何静态内容,如果您的静态内容在名为static的文件夹中,则必须包括{% load staticfiles %}和第二件事添加到project设置。py文件,例如 STATIC_DIR = os.path.join(BASE_DIR,'static') the the the the the the the the the the the the Project目录中的主要静态文件夹。

相关内容

最新更新