0Pricing
Python Academy · Lesson

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

  1. Routes and Views
  2. Templates with Jinja2
  3. Forms and Request Data
  4. Building a REST Endpoint
← Back to Python Academy