Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Flask Basics Welcome to Flask Multiply View

Chastin Davis
PLUS
Chastin Davis
Courses Plus Student 2,299 Points

I don't know why this isn't working.

Why isn't this working? I even tried what I placed in the comments. I have tried placing four routes as well, one for each combination possible between an int and a float and also for float to float and int to int.

What is going on here??

flask_app.py
from flask import Flask

app = Flask(__name__)


@app.route('/multiply/10/10')
@app.route('/multiply/12/12') # why doesnt @app.route('/multiply/<int:12>/<float: 12.5>') work???
@app.route('/multiply')
def multiply():
    return '25'

1 Answer

Keith Whatling
Keith Whatling
17,759 Points

So I'm answering this while eating dinner so it might go all over the place.

multiply needs to take two args from the app.route decorator.

def multiply(arg1, arg2):
    result = arg1 * arg2
    return result

They need to default to 5 so

def multiply(arg1=5, arg2=5):
    result = arg1 * arg2
    return result

Following that its just a case of copying what Kenneth does in the vid for ints and floats. make sure you have the @app.route('/multiply') at the top of the stack.

from flask import Flask

app = Flask(__name__)

@app.route('/multiply')
@app.route('/multiply/<int:arg1>/<int:arg2>')
@app.route('/multiply/<float:arg1>/<float:arg2>')
@app.route('/multiply/<int:arg1>/<float:arg2>')
@app.route('/multiply/<float:arg1>/<int:arg2>')
def multiply(arg1=5, arg2=5):
    result = arg1 * arg2
    return str(result)

Spoiler, if you are not mathy like me. (question 5-5 is just annoying, just return arg1 * arg2!)