烧瓶形式选择字段

我的 app.py 看起来像这样:


from flask import Flask,render_template,url_for,request

from flask_bootstrap import Bootstrap

from wtforms import SelectField

from flask_wtf import FlaskForm


app = Flask(__name__)

Bootstrap(app)



def Form(FlaskForm):

    panel_brand = SelectField('Panel Brand',choices=[('tr','trina'),('lo','longi'), ('ph','phono'), ('leap','leapton')])

    mounting = SelectField('Mounting',choices=[('tr','trina'),('lo','longi'), ('ph','phono'), ('leap','leapton')])

    inverter = SelectField('inverter',choices=[('Fronius10','Fronius 10'),('Fronius5','Fronius 5'), ('huawei6','huawei 6'), ('huawei8','huawei 8') , ('SolarEdge125','SolarEdge 12,5')])

    order_fulfillment = SelectField('orderfulfillment',choices=[('all3','Panels + inverter + mounting'),('Panels','Panels'),('panelsinv','Panels + Inverter'),('installer','By Installer')])



@app.route('/', methods=['GET','POST'])

def index():

    form = Form(FlaskForm)

    return render_template('index.html', form=form)

if __name__ == '__main__':

    app.run(debug=True)

我的索引.html看起来像这样


<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>Document</title>

</head>

<body>

    <form method="POST">

        {{ form.csrf_token }}

        {{ form.panel_brand }}

        {{ form.mounting }}

        {{ form.inverter }}

        {{ form.order_fulfillment }}

    <input type="submit">

    </form>

</body>

</html>

当我运行 app.py 文件时,它只显示提交按钮,而不是预期的下拉列表,,,, - 具有后续值。我想我在函数中缺少一些调用ID?我不确定如何以正确的语法做到这一点。任何人都可以帮我吗?panel_brandmountinginverterorder_fulfillmentindex()


守着星空守着你
浏览 73回答 2
2回答

长风秋雁

您的代码有一个函数,它需要有一个类。改变def Form(FlaskForm):...form = Form(FlaskForm)自class Form(FlaskForm)...form = Form(request.form)和

慕勒3428872

您的声明似乎正在对另一个对象进行子类化。form尝试:def&nbsp;index(): &nbsp;&nbsp;&nbsp;&nbsp;form&nbsp;=&nbsp;Form(request.form)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python