Python 3.x 从多个select表单中捕获值,并通过Flask发布
我需要捕获多个select表单vlaue(从MongoDB集合生成)并通过Flask路径发布到另一个MongoDB集合:Python 3.x 从多个select表单中捕获值,并通过Flask发布,python-3.x,mongodb,flask,Python 3.x,Mongodb,Flask,我需要捕获多个select表单vlaue(从MongoDB集合生成)并通过Flask路径发布到另一个MongoDB集合:recipes 以下是相关表格div: <form action="{{ url_for('insert_recipe') }}" method="POST" class="col s12"> ... <div class="input-field col s6 l6"> <i class="mat
recipes
以下是相关表格div:
<form action="{{ url_for('insert_recipe') }}" method="POST" class="col s12">
...
<div class="input-field col s6 l6">
<i class="material-icons prefix">warning</i>
<select multiple id="allergen_name" name="allergenlist">
<option value="" disabled selected>Choose allergens</option>
{% for allergen in allergens %}
<option value="{{allergen.allergen_name}}">{{allergen.allergen_name}}</option>
{% endfor %}
</select>
</div>
</div>
...
</form>
但是,仅捕获并发送第一个选定的选项
任何帮助都将不胜感激
编辑:
在查看时:
。。。重申我需要将
设置为_dict(flat=false)
以返回dict的所有值。请参见上面的编辑,正确的方法是:
# Send the form
@app.route('/insert_recipe', methods=['POST'])
def insert_recipe():
recipes = mongo.db.recipes
recipes.insert_one(request.form.to_dict(flat=False))
return redirect(url_for('get_recipes'))
另外,刚刚发现了一个副本,通知如下:
# Send the form
@app.route('/insert_recipe', methods=['POST'])
def insert_recipe():
recipes = mongo.db.recipes
recipes.insert_one(request.form.to_dict(flat=False))
return redirect(url_for('get_recipes'))