python - 如何使用 href url 传递变量?
问题描述
下面是我在 python 中使用烧瓶发送电子邮件的代码。
def sendPasswordResetLink(email, token):
message = Message()
message.subject = "Reset your password"
message.sender = "********@gmail.com"
message.recipients = email.split()
message.html = '<p>Hello there,</p>\n' \
'<p>Please click on the below link to reset your password</p>\n' \
'<a href=http://localhost:5002/resetpassword.html?token= +token+>'
mail.send(message)
线路有问题<a href....
。它没有在我收到的邮件中打印任何内容。我使用烧瓶邮件扩展。有人可以快速解决这个问题。正如我所说,我正在使用 Flask-mail 扩展,它提供了一个简单的界面来使用我们的 Flask 应用程序设置 SMTP 并从我们的视图和脚本发送消息。
预期行为 - 它应该向我的 gmail 发送主题为“重设密码”的邮件,并且在邮件正文中我应该在那里打招呼,请点击下面的链接重设密码。 http://localhost:5002/resetpassword.html?token=2
令牌是我与函数定义一起发送的参数。它包含请求重置密码的用户的用户标识。但是 URL 没有打印在我收到的邮件中。
解决方案
def sendPasswordResetLink(email, token):
message = Message()
message.subject = "Reset your password"
message.sender = "********@gmail.com"
message.recipients = email.split()
message.html = '<p>Hello there,</p>\n' \
'<p>Please click on the below link to reset your password</p>\n' \
'<a href="http://localhost:5002/resetpassword.html?token=' + token + '">Some message here</a>'
mail.send(message)
您的问题是您没有逃避'...'
字符串,因此永远不会添加token
到组合中。但是您也没有<a>
以</a>
. 那里没有消息。这里有一些例子。
推荐阅读
- regex - 最小长度的模式匹配?
- reactjs - 将 nextjs 应用程序部署到弹性 beantalk
- reactjs - Ant Design:如何将 this.props.form 传递给孩子
- gradle - 如何在多项目 Gradle 构建中指定通用模块版本
- sql - 如何使用 SQL Server 将字符串转换为 json 字符串
- docker - 从 docker 容器名称中删除随机字符串
- reactjs - 反应表动态页面大小,但有大小限制和分页
- c++ - 如何针对 c++ 最棘手的解析声明和填充三维向量作为结构的成员?
- java - 如何遍历对的数组列表以检索指定键的值?
- kotlin - 为什么返回调用者适用于`List`而不适用于`Map`?