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 to do it...

Let's demonstrate this with a small application. This application is very similar to the one we developed in Chapter 1, Flask Configurations.

The first thing to do is to add a new folder named templates under my_app. The application structure should look like the following directory structure:

flask_app/ 
    - run.py 
    my_app/ 
        - __init__.py 
        - hello/ 
            - __init__.py 
            - views.py 
        - templates 

We now need to make some changes to the application. The hello_world method in the views file, my_app/hello/views.py, should look like the following lines of code:

from flask import render_template, request @hello.route('/') @hello.route('/hello') def hello_world(): user = request.args.get('user', 'Shalabh') return render_template('index.html', user=user) ...
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