我正在尝试使用 Django CMS 和模板。但是在编辑模板时出错

I am trying to work with Django CMS and templates. but get an error while editing a template

我想要加载 css 和 js 文件。 它将显示错误 “第 15 行无效的块标记:'static'。您是否忘记注册或加载此标记?” 显示。但我已经正确地创建了数据。有人看到我的 html 文件中的错误吗?

这是我怀疑有问题的代码

    <!-- Bootstrap core CSS -->
    <link href="{% static  'vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="{% static  'css/modern-business.css' %}" rel="stylesheet">

这里是完整的代码

{% load cms_tags menu_tags sekizai_tags %}
<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE }}">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="{% page_attribute 'meta_description' %}">
    <meta name="author" content="Life Imaging Services GmbH">


    <title>{% page_attribute "page_title" %}</title>
    <!-- Bootstrap core CSS -->
    <link href="{% static  'vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="{% static  'css/modern-business.css' %}" rel="stylesheet">

    {% render_block "css" %}

</head>

<body>
{% cms_toolbar %}
<!-- Navigation -->
<nav class="navbar fixed-top navbar-expand-lg navbar-dark bg-dark fixed-top">
    <div class="container">
        <a class="navbar-brand" href="index.html">Start Bootstrap</a>
        <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse"
                data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false"
                aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarResponsive">
            <ul class="navbar-nav ml-auto">
                {% show_menu 0 100 100 100 %}
            </ul>
        </div>
    </div>
</nav>

<!-- Page Content -->
<div class="container">

    <!-- Page Heading/Breadcrumbs -->
    <h1 class="mt-4 mb-3">Full Width
        <small>Subheading</small>
    </h1>

    <ol class="breadcrumb">
        <li class="breadcrumb-item">
            <a href="index.html">Home</a>
        </li>
        <li class="breadcrumb-item active">Full Width</li>
    </ol>

    <p>Most of Start Bootstrap's unstyled templates can be directly integrated into the Modern Business template. You
        can view all of our unstyled templates on our website at
        <a href="https://startbootstrap.com/template-categories/unstyled">https://startbootstrap.com/template-categories/unstyled</a>.
    </p>

</div>
<!-- /.container -->

<!-- Footer -->
<footer class="py-5 bg-dark">
    <div class="container">
        <p class="m-0 text-center text-white">Copyright &copy; Your Website 2020</p>
    </div>
    <!-- /.container -->
</footer>

<!-- Bootstrap core JavaScript -->
<script src="{% static 'vendor/jquery/jquery.min.js' %}></script>
<script src="{% static 'vendor/bootstrap/js/bootstrap.bundle.min.js' %}></script>
{% render_block "js" %}

</body>

</html>

那是因为你没有加载 static

怎么办?

  1. 转到文件顶部
  2. 添加这个{% load static %}

现在您可以使用 static 因为您已经加载了它。

在此处阅读更多相关信息:https://docs.djangoproject.com/en/3.0/howto/static-files/

{% load static %}

您需要在页面顶部包含此标记。

在此处查看更多信息: https://docs.djangoproject.com/en/3.0/howto/static-files/