我有一个HTML页面,我有5个文本框,我想用MongoDB数据库中的数据填充。 结构如此:
app/ templates/ *.html (All HTML Templates here) forms.py views.py run.py所有表单都存储在forms.py文件中。 views.py文件具有路由。 当用户点击某个html页面时,文本框应该已经具有应该来自数据库的值。 我无法弄清楚如何填充这些。
我正在使用flask-wtf表格。 以下是forms.py文件的代码 - https://github.com/rahulw/Inventory-Management-for-a-Store/blob/master/app/forms.py 。
I have a HTML page where I have 5 text boxes which I want to be populated with data from my MongoDB database. The structure is so :
app/ templates/ *.html (All HTML Templates here) forms.py views.py run.pyAll the forms are stored in forms.py file. The views.py file has the route. When the user clicks on a certain html page, the text boxes should already have value which should come from the Database. I am not able to figure out how to populate those.
I am using flask-wtf for forms. Here is the code for the forms.py file -- https://github.com/rahulw/Inventory-Management-for-a-Store/blob/master/app/forms.py.
最满意答案
你正在使用什么数据库真的不重要。 基本上,您需要做的是更改表单的此属性:
form.post_body.data = page_content['body']如果page_content是您从数据库中提取的内容,则post_body是您要填充的特定表单字段,表单当然是您的表单。
然后,您可以像往常一样将此表单放入视图中,并填充数据!
Shouldn't really matter what DB you're using. Basically, what you need to do is change this attribute of your form:
form.post_body.data = page_content['body']Where page_content is the stuff you've pulled from the DB, post_body is your specific form field you want to populate, and form is of course your form.
You'd then throw this form into the view like you normally would, and the data will be populated!
更多推荐
发布评论