如何从html输入更新烧瓶中的Integer字段

时间:2019-06-12 06:20:07

标签: python flask

这是我的UI,当我单击+按钮时,我想更新该字段:

this is my UI I want to update the field when I click on +

我想使用flask创建类似Google的应用程序,我创建了一个输入类型以添加​​新的表单字段(当前不是表单字段)。我要更新编号。单击输入时的字段字段。

当我单击输入时,我正在发送发布请求。然后我检查它是否为发布请求,然后更新我的整数字段。但是它只更新一次。

abform.py

class Abform(FlaskForm):
    name = StringField('Name', validators=[DataRequired(), Length(min=2, max=20)])
    count = IntegerField('Count',default=1)
    submit = SubmitField('Submit')


@app.route("/home",methods=['POST','GET'])
def home():
    form=Abform()
    if request.method=='POST':
        form.count.data+=1
     list_type= ['int', 'string', 'text', 'boolean']
    return render_template('home.html', list_type=list_type,form=form)

home.html

    <form method='POST' action="{{url_for('home')}}">

            <input type="submit" value='+'>
            </br>
        </form>
            <form method='POST' action="{{url_for('home')}}">
                <div class="form-group"> 

            {% for i in range(form.count.data)%}
                {{i+1}}
                {{ form.name(class="form-control form-control-lg is-invalid") }}
                    <select name= list_type method="GET" action="/">
                    {% for c in list_type %}
                    <option value= "{{c}}" SELECTED>{{c}}</option>"
                    {% endfor %}

                </select>
              <button type="button" data-toggle="fieldset-add-row" data-target="#phone-fieldset">-</button>
            </br>
            {% endfor %}
             {{ form.submit(class="btn btn-outline-info") }}
        </div>
        </div>
      </form>

我希望当我单击HTML文件第二行的按钮(输入类型)时得到另一个字段。

0 个答案:

没有答案