模板中多个表的flask selectfield默认值

当我使用Jinja语法在模板中创建多个表时,我需要一个解决方案来通过HTML模板在烧瓶选择表单中预设值。我知道在路由中直接使用from pathlib import Path p = Path(path_here) # so much information about the file print(p.name,p.parent,p.parts[-2]) print(p.resolve()) print(p.stem) form.default时需要预先设置一次的解决方案,但是如果需要动态更改该如何解决?

forms.py

form.process()

models.py

class formSupplierName(flaskForm):
    name = SelectField('name',coerce=str)
    submit = SubmitField('sumbit')

在routes.py

class Supplier(db.Models):
    id = db.Column(db.Integer,primary_key=True)
    name = db.Column(db.String(120)

index.html

list = [1,2,3] # list can be anything length. In my application it is list db.relationship 
form = formSupplierName()
form.name.choices = [(g.id,g.llc_name) for g in Supplier.query.all()]
#[(1,test1),(2,test2),(3,test3)]

在这种情况下,我的HTML模板中有3个表,{%for i in list%} <table> <thead> <tr> <th>name</th> </tr> </thead> <tbody> <tr> <td onchange="changeSupplier(event)">{{form.name=supp.llc_name)}}</td> </tr> </tbody> </table> {%endfor%} 总是form.name,但是我需要以下内容:

'test1'
wr5279 回答:模板中多个表的flask selectfield默认值

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3133135.html

大家都在问