小编cas*_*ual的帖子

18
推荐指数
2
解决办法
2万
查看次数

SQLAlchemy/WTForms:为 QuerySelectField 设置默认选定值

此[示例][1]在 Flask 中使用 WTForms 和 SQLAlchemy 设置表单并向表单添加 QuerySelectField 。我没有使用flask.ext.sqlalchemy,我的代码:

ContentForm = model_form(Content, base_class=Form)
ContentForm.author = QuerySelectField('Author', get_label="name")
myform = ContentForm(request.form, content)
myform.author.query = query_get_all(Authors)
Run Code Online (Sandbox Code Playgroud)

现在我想设置 QuerySelectField 的 selectlist 的默认值

尝试default在 QuerySelectField 中传递 kwarg 并设置selected属性。什么都没起作用。我错过了一些明显的东西吗?有人可以帮忙吗?

python sqlalchemy selection flask wtforms

6
推荐指数
1
解决办法
6749
查看次数