Passing an integer via URL in Flask App

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

One of the key skills for web apps will be to pass a variable using the URL.

Edit the 'app.route'

You need to add the parameter in '<' & '>' brackets. The 'int' is the data type:

@app.route("/product/<int:param>/")

Edit the def

You will need to add the name of the parameter from the 'app.route' string:

def go_to(param):

Using the parameter

This variable is now available in the entire 'def' for this route.