【问题标题】:jinja2.exceptions.TemplateSyntaxError: unexpected '%'jinja2.exceptions.TemplateSyntaxError: 意外的 '%'
【发布时间】:2018-02-18 13:43:50
【问题描述】:

当我使用“GET”方法调用 /buy 时,我遇到了这个错误:

jinja2.exceptions.TemplateSyntaxError: 意外'%'

buy.html:模板文件

{% extends "layout.html" %}

{% block title %}
 Buy
{% endblock %}

{% block main %}
    <form action="{{ url_for('buy') }}" method="post">
        <fieldset>
            <div class="form-group">
                <input autocomplete="off" autofocus class="form-control" 
                 name="symboll" placeholder="Symbol" type="text"/>
            </div>
            <div class="form-group">
               <input class="form-control" autocomplete="off" autofocus 
                name="number" placeholder="number of share" type="text"/>
            </div>
            <div class="form-group">
                <button class="btn-default btn" type="submit"> Buy </button>
            </div>
       </fieldset>
    </form>
{% endblock %}    

应用程序.py:

@app.route("/buy", methods=["GET", "POST"])
@login_required
def buy():
   if request.method == "GET":
       return render_template("buy.html")

【问题讨论】:

  • 能否打印整个堆栈跟踪,或者提供 layout.html,好吗?丢失的 % 可能在 layout.html 中。
  • 好的,我会打印它@JakeConway
  • 您应该将它们编辑到主帖子本身 - Stack Overflow 要求所有帖子“答案”都是主要问题的解决方案。

标签: python flask jinja2


【解决方案1】:

我想你的错误是在login.html 或类似的地方提出的。在模板中查找由您的 login_required 装饰器呈现的错误。

【讨论】:

  • 登录代码和buy.html的代码一样,我不明白我的代码有什么问题
  • 您能提供完整的堆栈跟踪消息吗?
猜你喜欢
  • 1970-01-01
  • 2019-11-07
  • 2020-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-10
  • 1970-01-01
  • 2018-01-30
相关资源
最近更新 更多