如何将列表发送到mongodb集合?

时间:2018-12-11 01:29:08

标签: python html arrays mongodb

我真的很难理解我如何从允许用户在html模板上制作的表单中发送列表,以正确地在mongodb的数组中保存多个值。例如,如果用户想输入成分或说明键的多个值。有没有一种设置方法,以便mongodb知道这是一个值列表,而不仅仅是一个值列表?这是我的HTML:

{% extends 'base.html' %} {% block content %}
    <h3>Add Task</h3>
    <div class="row">
        <form  action="{{ url_for('insert_recipe') }}" method="POST" class="col s12">
            <div class="row">
                    <div class="input-field col s12">
                        <i class="material-icons prefix">poll</i>
                        <select id="category" name="category_name">
                      <option value="" disabled selected>Choose Category</option>
                      {% for cat in categories %}
                          <option value="{{cat.category_name}}">{{cat.category_name}}</option>
                      {% endfor %}
                    </select>
                        <label>Category</label>
                    </div>
                </div>  

            <div class="row">    
                <div class="input-field col s12">
                    <i class="material-icons prefix">assignment</i>
                    <input id="recipe_name" name="recipe_name" type="text" class="validate">
                    <label for="icon_prefix">Recipe Name</label>
                </div>
            </div>
             <div class="row">
                <div class="input-field col s12">
                    <i class="material-icons prefix">subject</i>
                    <textarea name="recipe_author" id="recipe_author" class="materialize-textarea"></textarea>
                    <label for="icon_telephone">Author</label>
                </div>
            </div>
            <div class="row">
                <div class="input-field col s12">
                    <i class="material-icons prefix">subject</i>
                    <textarea name="ingredients" id="ingredients" class="materialize-textarea"></textarea>
                    <label for="icon_telephone">Ingredients</label>
                </div>
            </div>
            <div class="row">
                <div class="input-field col s12">
                    <i class="material-icons prefix">subject</i>

                    <textarea name="directions" id="directions" class="materialize-textarea"></textarea>
                    <label for="icon_telephone">Instructions</label>
                </div>
            </div>
            <div class="row">
                <div class="input-field col s12">
                    <i class="material-icons prefix">subject</i>
                    <textarea name="prep_time" id="prep_time" class="materialize-textarea"></textarea>
                    <label for="icon_telephone">Prep-Time</label>
                </div>
            </div>
            <div class="row">
                <div class="input-field col s12">
                    <i class="material-icons prefix">subject</i>
                    <textarea name="cooking_time" id="cooking_time" class="materialize-textarea"></textarea>
                    <label for="icon_telephone">Cooking Time</label>
                </div>
            </div>
            <div class="row">
                <button class="btn waves-effect waves-light" type="submit">Add Recipe
                    <i class="material-icons right">playlist_add</i>
                 </button>
            </div>
        </form>
    </div>
    {% endblock %}

0 个答案:

没有答案