如何在 Flask 中提交后在同一页上打印 html 表单详细信息?

How to print html form details on the same page after submit in flask?

单击提交时显示没有 select 值的空表单。如何在同一页面上保留图像和 select 选项以及选项列表,即使在单击提交后也是如此。我已经提供了尽可能多的细节。提前致谢!!

这是dashboard.py

@app.route('/',methods=["GET","POST"])
def home():
     if request.method=="GET":
          #tl contains a list of topic list
          return render_template("main.html",topics=tl)
     else:
          #images_list contains a list of images
          return render_template("dashboard.html",img=images_list)

这是main.html

<html>
<body>
<div class="header">

  <img src="static\twitter1.png" alt="logo" />
  <h1>Twitter Dashboard</h1>

</div>

<form action = "/" method = 'POST'>
    <div class="selectdiv">
<b>Topic</b>
<select name="topic_list">

{% for each in topics %}

<option value="{{each}}" selected="{{each}}">{{each}}</option>

{% endfor %}

</select>


<input type="submit" value="Submit"/>
        </div>
</form>
</body>

    {% block content %}
    {% endblock content %}

</html>

这是dashboard.html

{% extends "main.html"%}

{% block content %}

<body>

{% for row in img1 %}
<img src="static\images\{{row}}" >
{%endfor%}

</body>

{%endblock%}

结果:-

您没有将 select 选项传递到仪表板页面。

@app.route('/',methods=["GET","POST"])
def home():
    if request.method=="GET":
       #tl contains a list of topic list
       return render_template("main.html",topics=tl)
    else:
      #images_list contains a list of images
      return render_template("dashboard.html",topics=tl,img=images_list)