July 2019
Beginner to intermediate
302 pages
9h 38m
English
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) ...