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 trialDaniel Fragoso
5,333 PointsError 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'".
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
18,823 PointsYou 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
5,333 PointsThank you very much for your answer!
Kent Åsvang
18,823 PointsYou are very welcome.
Fergus Clare
12,120 PointsKenneth 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>')