A
A
Alexander Pavlov2021-06-10 21:07:58
Flask
Alexander Pavlov, 2021-06-10 21:07:58

Why does the data from the dropdown list disappear after a post request in FLASK?

Hello.

There is a dropdown list in html template:

<label>
    Выбери продавца:
      <select name="seller" class="seller form-select">
        <option value=""></option>
        {% for name_item in name_seller %}
          {% for seller in name_item %}
            <option value="{{ seller }}">{{ seller }}</option>
          {% endfor %}
        {% endfor %}
      </select>
    </label>


This list is in a form with action="POST", when you click on the submit button, the data disappears from the list.

The function looks like this, that is, the data is added to the list from the database:

def get_name_seller():
        cursor.execute("SELECT name_seller FROM receipt GROUP BY name_seller ORDER BY name_seller")
        name_sellers = cursor.fetchall()
        return render_template("index.html", name_seller=name_sellers)

The question is why and how to overcome it?

The problem occurs both locally and on the server.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-06-10
@Sanchez9891

Because when forming a drop-down list, you do not mark the selected element in any way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question