Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,822 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!

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>')