简体   繁体   English

python flask:如果request.method == 'POST',则附加到表单

[英]python flask: append to form if request.method == 'POST'

I have a html form and on post, I can pass the form into mongodb我有一个 html 表单,在发布时,我可以将表单传递给 mongodb

if request.method == 'POST': 
        new_employee.insert_one(request.form.to_dict())

This works... But how would you append additional string when form is post这有效......但是当表单发布时你将如何附加额外的字符串

for example例如

if request.method == 'POST': 
        employee_username = (request.form['employee_first_name'] + '.' + request.form['employee_last_name'])

        new_employee.insert_one(request.form.to_dict())


How would you append for example 'employee_username' : employee_username您将如何附加例如“employee_username”:employee_username

Try this below :试试这个:

if request.method == 'POST': 

        post_data = request.form.to_dict()
        employee_username = (request.form['employee_first_name'] + '.' + request.form['employee_last_name'])
        post_data['employee_username'] = employee_username
        new_employee.insert_one(post_data)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM