簡體   English   中英

在 flask 中提交后,如何在同一頁面上打印 html 表單詳細信息?

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

單擊提交時顯示沒有 select 值的空表單。 即使單擊提交后,如何在同一頁面上保留圖像和 select 選項與選項列表。 我已經提供了盡可能多的細節。 提前致謝!!

這是儀表板.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)

這是主要的。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>

這是儀表板。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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM