July 2019
Beginner to intermediate
302 pages
9h 38m
English
To demonstrate the flashing of messages, we will flash messages upon the product's creation.
First, we will add a secret key to our app configuration in flask_catalog_template/my_app/__init__.py:
app.secret_key = 'some_random_key'
Now, we will modify our create_product() handler in flask_catalog_template/my_app/catalog/views.py to flash a message to the user regarding the product's creation.
Also, a small change has been made to this handler; now, it will be possible to create the product from a web interface using a form:
from flask import flash, redirect, url_for @catalog.route('/product-create', methods=['GET', 'POST']) def create_product(): if request.method == 'POST': name = request.form.get('name') price = request.form.get('price') ...