Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Flask,jinja2-一个接一个地动态附加模板_Html_Templates_Flask_Jinja2_Python 3.6 - Fatal编程技术网

Html Flask,jinja2-一个接一个地动态附加模板

Html Flask,jinja2-一个接一个地动态附加模板,html,templates,flask,jinja2,python-3.6,Html,Templates,Flask,Jinja2,Python 3.6,我正在建造一个聊天机器人。很少有像login.html、messages.html、transaction.html等子模板。我想在base.html中动态附加这些模板。我正在所有这些模板中扩展base.html。我的问题是一次只渲染一个模板。有没有办法一个接一个地追加这些模板?我使用了{%include%},但它是一种静态方法。我需要动力 printer.py看起来像- @app.route('/respond', methods=['GET','POST']) def respond_def

我正在建造一个聊天机器人。很少有像login.html、messages.html、transaction.html等子模板。我想在base.html中动态附加这些模板。我正在所有这些模板中扩展base.html。我的问题是一次只渲染一个模板。有没有办法一个接一个地追加这些模板?我使用了{%include%},但它是一种静态方法。我需要动力

printer.py看起来像-

@app.route('/respond', methods=['GET','POST'])
def respond_def():
   message = request.form['message_input']
   if message == "l":
       return render_template('printer/login.html')
   elif message == "t":
       return render_template('printer/transactionID.html')
base.html看起来像-

//some code here
<li>
    {% block template %}{% endblock %}
</li>
//some code here
{% extends "base.html" %}
{% block template %}
<div> Message template called </div>
{% endblock %}
//这里有一些代码
  • {%block-template%}{%endblock%}
  • //这里有一些代码
    message.html看起来像-

    //some code here
    <li>
        {% block template %}{% endblock %}
    </li>
    //some code here
    
    {% extends "base.html" %}
    {% block template %}
    <div> Message template called </div>
    {% endblock %}
    
    {%extends“base.html”%}
    {%块模板%}
    消息模板调用
    {%endblock%}
    
    我解决了它。 我在printer.py中列出了一个模板列表,然后在用户要求时将这些模板附加到base.html中

    打印机.py

    dictionary = []
    // append name of template in this whenever needed.
    return render_template('printer/base.html', dictionary=dictionary)
    
    base.html

    {% for d in dicts %}
    {% set template = 'printer/' + d + '.html' %}
    // can add conditions for different templates
    {% include template %}
    {% endfor %}