简体   繁体   English

如何使用 python/flask 添加超链接

[英]How can I add a hyperlink with python/flask

I am using Flask to build a website.我正在使用 Flask 建立网站。 I have an html form that will add a subscriber to a database.我有一个 html 表单,它将向数据库添加订阅者。 When I update the website, the subscribers will get an email notification.当我更新网站时,订阅者将收到 email 通知。 How can I add to the email a hyperlink to allow them to choose to unsubscribe.我怎样才能给 email 添加一个超链接,让他们选择退订。 (I have a function set up already that I can delete the subscribers, but I want them to have the option of removing themselves.) Any ideas? (我已经设置了一个 function,我可以删除订阅者,但我希望他们可以选择删除自己。)有什么想法吗?

here is my email code这是我的 email 代码

 subscriber_message = "You have been subscribed. Thank you.\n\n\n\n\n\n\n\nIf you wish to be removed from the subscription list" click here.
 server=smtplib.SMTP("smtp.gmail.com", 587)
 server.starttls()
 server.login(my_email, pw)
 server.sendmail(my_email, subscriber_email, subscriber_message)

I want the "click here."我想要“点击这里”。 to be the hyperlink成为超链接

here is the code I want it to receive when the link is clicked.这是我希望它在单击链接时收到的代码。

@auth.route('/delete-subscribers', methods=['POST'])
def delete_subscribers():
    sub = json.loads(request.data)
    subscribersId = sub['subscribersId']
    sub = Subscribers.query.get(subscribersId)
    if sub:
        db.session.delete(sub)
        db.session.commit()

    else:
        flash('Subscriber does not exist in database.', category='error')

    return jsonify({})

Any ideas?有任何想法吗? Thank you.谢谢你。

add to the email a hyperlink添加到 email 超链接

Send actual HTML payload with <a href="http://unsubscribe-here.com">Unsubscribe</a> rather than a raw string.使用<a href="http://unsubscribe-here.com">Unsubscribe</a>而不是原始字符串发送实际的 HTML 负载。

You may use Jinja2 templates to help with that.您可以使用 Jinja2 模板来帮助解决这个问题。

Then it's up to the email client to properly render HTML content.然后由 email 客户端正确呈现 HTML 内容。

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

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