Flask:一个模板没有正确扩展基础

时间:2017-04-30 16:40:28

标签: python html templates flask

我的某个模板( offers_overview.html )未正确继承我的 base.html 模板。相反,它只输出 offers_overview.html 中给出的html而不使用 base.html 中的html。

我有另一个模板( customer_overview.html ),其中包含与offers_overview.html完全相同的html,并且它完全可以扩展base.html。这让我感到困惑。 我做错了什么?

以下是我的views.py对 offers_overview 的看法:

@mod.route('/<username>/<int:inquiry_id>', methods=['GET', 'POST'])
@login_required
def show_offers_overview(username, inquiry_id):
 user = Customers.query.filter_by(cusername=username).first()
 inquiry = Inquiry.query.filter_by(iid=inquiry_id).first()

 if (user or inquiry) is None:
    flash('User %s or inquiry %s is not found.' % (username, inquiry_id))
    return redirect(url_for('user.user_overview', username=user.cusername))
 return render_template('offers_overview.html', inquiry=inquiry)

以下是 customer_overview 的views.py外观:

@mod.route('/<username>', methods=['GET', 'POST'])
@login_required
def user_overview(username):
 user = Customers.query.filter_by(cusername=username).first()
 if user is None:
    flash('User %s not found.' % username)
    return redirect('/user/login')
 return render_template('customer_overview.html', customer=user)

这是offers_overview.html:

{% extends 'base.html' %}

{% block title %}Offers overview{% endblock title %}
{% block body %}
  <h2>Not important {{ inquiry.worktitle }}</h2>
  <br>
  <h3>Future</h3>
  <br>
  <h3>Present</h3>
  <br>
  <h3>Past</h3>
{% endblock body %}

与customer_overview.html中的代码完全相同,但查询被更改为客户。

我尝试将要在 show_offers_overview()中呈现的模板更改为customer_overview。结果是子模板没有继承基本模板。

更新 这就是模板的结构:

|project\
   |app\
      |templates\
         |--base.html
      |user\
         |templates\
            |--customer_overview.html
            |--offers_overview.html
         |--__init__.py
         |--views.py

0 个答案:

没有答案
相关问题