Python Flask Basics Welcome to Flask Multiply View

William Ray Noble
William Ray Noble
21,960 Points

Flask 5 * 5 question

So I'm not sure what I'm doing wrong. Can you not use default parameters in Flask? I tried putting the numbers directly into the route path but that didn't work either. TIA

flask_app.py
from flask import Flask

app = Flask(__name__)

@app.route('/multiply/<int:num1>/<int:num2>')
def multiply(num1=5, num2=5):
    return str(num1 * num2)
    #return '{} * {} = {}'.format(num1, num2, num1 * num2)

1 Answer

Josh Keenan
Josh Keenan
19,382 Points

You need to retain the route for multiply as well as with input.

@app.route('/multiply')
@app.route('/multiply/<int:num1>/<int:num2>')