简体   繁体   中英

How can I add a hyperlink with python/flask

I am using Flask to build a website. I have an html form that will add a subscriber to a database. When I update the website, the subscribers will get an email notification. How can I add to the email a hyperlink to allow them to choose to unsubscribe. (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?

here is my email code

 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

Send actual HTML payload with <a href="http://unsubscribe-here.com">Unsubscribe</a> rather than a raw string.

You may use Jinja2 templates to help with that.

Then it's up to the email client to properly render HTML content.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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