我的 app.py 看起來像這樣:from flask import Flask,render_template,url_for,requestfrom flask_bootstrap import Bootstrapfrom wtforms import SelectFieldfrom flask_wtf import FlaskFormapp = 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>當(dāng)我運(yùn)行 app.py 文件時,它只顯示提交按鈕,而不是預(yù)期的下拉列表,,,, - 具有后續(xù)值。我想我在函數(shù)中缺少一些調(diào)用ID?我不確定如何以正確的語法做到這一點(diǎn)。任何人都可以幫我嗎?panel_brandmountinginverterorder_fulfillmentindex()
2 回答

長風(fēng)秋雁
TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超7個贊
您的代碼有一個函數(shù),它需要有一個類。
改變
def Form(FlaskForm):
...
form = Form(FlaskForm)
自
class Form(FlaskForm)
...
form = Form(request.form)
和

慕勒3428872
TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超6個贊
您的聲明似乎正在對另一個對象進(jìn)行子類化。form
嘗試:
def index(): form = Form(request.form)
添加回答
舉報
0/150
提交
取消