Python flask模板推断

问题描述 投票:1回答:1

当我尝试使用继承块时,我的模板中有错误在将login.html转换为html之前,一切正常,基本上所有内容都来自base.html

我的html文件如下:

base.html:

<!DOCTYPE html>
<html>
    <head>
        {% block head %}
        <title> {% block title %} {% endblock %} | Company Name</title>
        {% endblock %}
    </head>

    <body>
        {% block body}

        {% endblock %}
    </body>
</html>

login.html:

{% extends "base.html" %}

{% block title %}Login{% endblock %}

{% block body %}
  <form method="POST">
    <label for="name_question">What is your name? <br>
    <input type="text" name="name"> <br>
    <input type="submit" name="submit" value="Submit"> <br>
  </form>

  {% if name %}
    <h1>Hello, {{name}}!</h1>
  {% endif %}

{% endblock body %}
python html django-templates flask-login
1个回答
0
投票
您尝试做的事情似乎没有错。这可能是由于许多其他原因引起的,主要是以下任何原因:

    我认为对基本模板的引用是相对于您的
  • TEMPLATE_DIR。尝试不同的操作,例如将两个模板都放在相同级别等。
  • 检查两个模板中的所有标签,以确保它们都是格式正确
  • 检查文件的编码。如果是UTF-8,请尝试禁用两个文件中都有BOM。
  • 也许您的目录设置有问题。尝试硬编码检查的绝对路径

我的猜测将是最后一点。

© www.soinside.com 2019 - 2024. All rights reserved.