Python Flask中的多模板绘制

Python Flask中的多模板绘制,python,flask,jinja2,Python,Flask,Jinja2,我需要呈现多个模板,我已经看到了这个链接,但可能我仍然在做一些错误的事情 这是base.html <body> <div> <p>This is a templete base</p> </div> {% block content %}{% endblock content %} {% include "page_2.html" %} </body> 这是pytho

我需要呈现多个模板,我已经看到了这个链接,但可能我仍然在做一些错误的事情

这是base.html

<body>

    <div>
        <p>This is a templete base</p>
    </div>

    {% block content %}{% endblock content %}
    {% include "page_2.html" %}


</body>
这是python代码(我假设我做错了什么?)


我立即意识到有两个错误:

1) 您已在同一管线下定义了2条管线

2) 页面_1需要变量abc,因为它包括页面_2

改为:

@app.route('/route_1') # <- from '/'
def check():
    return render_template("page_1.html", data=blah, abc=abc) # <- page 1 inherits a need for 'abc'

@app.route('/route_2') # <- from '/'
def wow():
    return render_template("page_2.html", abc=abc)

@app.route('/route_1')#实际提问很有帮助,说明什么不起作用,以及实际发生的错误或意外行为是什么。但它不会出现在同一页面中。很明显,如果我从另一个路由转到另一个路由,页面将被呈现,但我需要在一个路由中呈现它page@TheTechGuy但这就是Flask(和Django)在基本层面上的功能。如果在同一条路径下定义两个函数,它将无法实现预期的效果。时期除此之外,你的问题并没有提供关于你的错误是什么或者你想做什么的信息,所以除了指出你肯定做不到的事情之外,我不能猜测你的意图。
{{abc}}
blah = ['blah', 'blah', ' blah']
abc = ['abc', "abc ?", "abc"]

@app.route('/', methods = ['GET', 'POST'])
def check():
    return render_template("page_1.html", data=blah)

@app.route('/', methods = ['GET', 'POST'])
def wow():
    return render_template("page_2.html", abc=abc)
@app.route('/route_1') # <- from '/'
def check():
    return render_template("page_1.html", data=blah, abc=abc) # <- page 1 inherits a need for 'abc'

@app.route('/route_2') # <- from '/'
def wow():
    return render_template("page_2.html", abc=abc)