热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Flask邮件api,没有正确获取请求varialbe-Flaskmailapi,notgettingrequestvarialbeproperly

ImtryingtoaccessarequestfromanHTMLform,andsenditasamail,butIgetamailwithaval

I'm trying to access a request from an HTML form, and send it as a mail, but I get a mail with a value of "None",

我正在尝试从HTML表单访问请求,并将其作为邮件发送,但我收到的邮件的值为“无”,

here is my code:

这是我的代码:

@app.route("/about", methods=['GET', 'POST'])
def send_message():
     name = request.form.get('name')
     msg = Message(
       subject='Hello ' + str(name),
       sender='kristofferlocktolboll@gmail.com',
       recipients=
           ['kristofferlocktolboll@gmail.com'],
       html=render_template("about.html"))
    mail.send(msg)
    confirm_msg = "Your message has been sent!"
    return render_template("about.html", confirm_msg=confirm_msg)

I think it might be due to the fact, that I'm casting the object into a string, but if I don't do that, I will get an error due to making a conjunction between a String and another object

我认为可能是因为我将对象转换为字符串,但如果我不这样做,我会因为在String和另一个对象之间建立连接而得到错误

EDIT:

编辑:

here is my html code, i have tried both using post and get as the method, but nothing works.

这是我的HTML代码,我已尝试使用post和get作为方法,但没有任何作用。

  
                First name: 

Last name:

Email-address:

Phone-number:

Enter your message:

EDIT 2:

编辑2:

When ever i try to display the confirm_msg it is displayed instantly, when i enter the site.

当我尝试显示confirm_msg时,它会在我进入网站时立即显示。

{{confirm_msg}}

1 个解决方案

#1


0  

Firstly you must add CSRF_TOKEN for your form: ... .....

首先,您必须为表单添加CSRF_TOKEN:

.. .....

Also can you tell us in which page you are trying to see

{{confirm_msg}}

?

您也可以告诉我们您要在哪个页面看到

{{confirm_msg}} ?


推荐阅读
author-avatar
书友60061807
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有