Forms and Request Data
Process user input.
The request Object
Flask gives every view access to a global request object holding all the incoming data: form fields, query strings, JSON, headers, and more.
from flask import Flask, request
app = Flask(__name__)
# request is available inside any view
print('request carries the incoming data')Query String Parameters
Data after ? in the URL lives in request.args. Use .get() to read a value safely.
from flask import Flask, request
app = Flask(__name__)
@app.route('/search')
def search():
term = request.args.get('q', '')
return 'Searching for ' + term
print('/search?q=cats -> request.args')All lessons in this course
- Routes and Views
- Templates with Jinja2
- Forms and Request Data
- Building a REST Endpoint