簡體   English   中英

如何從 WTForm 獲取所有數據?

[英]How to GET all the ALL DATA from WTForm?

**如何使用字典或列表中的單個命令獲取 wtf 表單中的所有數據,而無需編寫這么多代碼行,指定表單中的每個元素並單獨獲取數據 **

@app.route('/add', methods=['POST', 'GET'])
def add_cafe():
    form = CafeForm()
    if form.validate_on_submit():
        print("True")
        cafe_name = form.cafe_name.data
        cafe_location = form.cafe_location.data
        opening_time = form.opening_time.data
        closing_time = form.closing_time.data
        coffee_rating = form.coffee_rating.data
        wifi_strength_rating = form.wifi_strength_rating.data
        power_socket_availability = form.power_socket_availability.data
    return render_template('add.html', form=form)

wtforms文檔說那是Form.data

包含每個字段數據的字典。

換句話說,

@app.route('/add', methods=['POST', 'GET'])
def add_cafe():
    form = CafeForm()
    if form.validate_on_submit():
        data = form.data
        print("True", data)
        # ...
    return render_template('add.html', form=form)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM