【问题标题】:static files in python using csspython中使用css的静态文件
【发布时间】:2021-08-26 19:55:23
【问题描述】:
<html>
    <head>
        <title>
        <link rel="stylesheet" href="//maxcdn.bootstrap.com/bootstrap/3.2.0/css/bootstrap.min.css">
        <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
        <link rel="stylesheet" href={% static 'css/blog.css' %}">
        <link href="//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
    </head>
    <body>
        <div>
            <h1><a href=" ">Cradle's Blog</a></h1>
        </div>
        {{ % for post in posts }}
            <div>
                <p> published: {{ post.published_date }}</p>
                <h1><a href=" ">{{ post.title }}</a></h1>
                <p>{{ post.text|linebreaksbr }}</p>
            </div>
        {{% endfor %}}
    </body>
</html>

我得到状态的错误;第 6 行的块标记无效:“静态”。您是否忘记注册或加载此标签?...如何执行此操作? 我收到一个新错误:无法解析剩余部分。 '%for post in posts %' from '% for post in posts %'

【问题讨论】:

    标签: python django django-templates django-staticfiles


    【解决方案1】:

    你需要先加载static template tags/filters [Django-doc],所以:

    {% load static %}
    <html>
        …
    </html>

    此外,模板标签写在{% … %}之间,而不是{{% … %}}之间。因此,您应该使用:

    {% for post in posts %}{% endfor %}

    【讨论】:

    • 谢谢...晚上好,但我收到一个新错误,提示 Templatesyntaxerror at / could not parse the rest: '% for post in posts %' from '% for post in posts %'
    • @CodedX: 那是因为你把模板标签写错了,见编辑。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-18
    • 2022-11-16
    • 1970-01-01
    • 2020-11-16
    • 2019-03-05
    • 1970-01-01
    相关资源
    最近更新 更多