Skip to Content
Flask Framework Cookbook - Second Edition
book

Flask Framework Cookbook - Second Edition

by Shalabh Aggarwal
July 2019
Beginner to intermediate
302 pages
9h 38m
English
Packt Publishing
Content preview from Flask Framework Cookbook - Second Edition

How it works...

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.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Writing a Web Application with Flask

Writing a Web Application with Flask

Doug Farrell
Mastering Flask

Mastering Flask

Jack Stouffer

Publisher Resources

ISBN: 9781789951295Supplemental Content