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

Daniel Fragoso
Daniel Fragoso
5,333 Points

Error message doesn't make sense for what I'm being requested to do

I'm at step 2 out of 5 which says I'm supposed to add a new route to multiply() with 2 arguments that should have defaults of 5. I'm pretty sure I did that but when I submit I get an error message saying "Didn't get a 200 at '/multiply/10/10'".

flask_app.py
from flask import Flask

app = Flask(__name__)

@app.route('/<a>/<b>')
@app.route('/multiply')
def multiply(a=5, b=5):
    return (str(5*5))

3 Answers

Kent Åsvang
Kent Åsvang
18,823 Points

You are not that far off:

from flask import Flask

app = Flask(__name__)
""" up until this point everything is a-okay, its the first app.route that is the problem,
     heres how it should be : 
    @app.route('/multiply/<int:a>/<int:b>')"""
@app.route('/<a>/<b>')
@app.route('/multiply')
def multiply(a=5, b=5):
    """ I would also change the return statement to be : 
          return '{}'.format(a * b)
         You see, the way you have written it makes it hardcoded to return 5 times 5 no matter what the input is, 
         You want to make use of the values that are passed in the url. """
    return (str(5*5))

Here is my solution:

from flask import Flask

app = Flask(__name__)


@app.route('/multiply')
@app.route('/multiply/<int:a>/<int:b>')
def multiply(a = 5, b = 5):
    ab = a * b
    return '{}'.format(ab)
Daniel Fragoso
Daniel Fragoso
5,333 Points

Thank you very much for your answer!

Fergus Clare
Fergus Clare
12,120 Points

Kenneth Love : this challenge has errors. In order for the user to get a successful response, she is required to include:

@app.route('/multiply')

The root route (nice...) of multiply is not required when params are being passed in the url. For this reason, a route as outlined below needs to be accepted:

@app.route('/multiply/<int:n1>/<int:n2>')