July 2019
Beginner to intermediate
302 pages
9h 38m
English
To send an email on category creation, we need to make the following changes in my_app/catalog/views.py:
from my_app import mail
from flask_mail import Message
@catalog.route('/category-create', methods=['GET', 'POST'])
def create_category():
# ... Create category ... #
db.session.commit()
message = Message(
"New category added",
recipients=['some-receiver@domain.com']
)
message.body = 'New category "%s" has been created' % category.name
mail.send(message)
# ... Rest of the process ... #
Here, a new email will be sent to the list of recipients from the default sender configuration that we did.