2
我試圖從下拉框中獲取值到變量中,然後存儲它。我是Flask的新手,無法在有關它的文檔中找到任何內容。 但我不知道如何從request.form或任何其他原因的下拉列表中獲取值。如何從下拉列表中獲取價值
我在app.py
@app.route('/add', methods=['POST'])
def add_entry():
if not session.get('logged_in'):
abort(401)
title = request.form['title']
link = request.form['link']
shown = request.form['shown']
#I hardcoded the id here too see basic function.
kate = Category.query.filter_by(id = 2).first()
add_into = Entries(title, link, shown, kate)
db.session.add(add_into)
db.session.commit()
這裏燒瓶代碼是它的HTML。
<form action="{{ url_for('add_entry') }}" method=post class="add-entry custom">
<dl>
<dt>Title:
<dd><input type=text size=120 name=title>
<dt>Link:
<dd><input type=text size=120 name=link>
<dt>Shown:
<dd><input type=text size=120 name=shown>
<label for="customDropdown">Category</label>
<select style="display:none;" id="customDropdown">
{% for c in cate %}
{% if c.id == 1 %}
<option id="{{ c.name }}" name="{{ c.name }}" SELECTED>{{ c.name }}</option>
{% else %}
<option>{{ c.name }}</option>
{% endif %}
{% endfor %}
</select>
<dd><input class="success button" type=submit value=Post it!>
</dl>
</form>