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

Erwan Mba Mba
Erwan Mba Mba
2,711 Points

Hey, how do ou solve the challenge on multiply view: Add a view named multiply. Give multiply a route named /multiply.

Add a view named multiply. Give multiply a route named /multiply. Make multiply() return the product of 5 * 5. Remember, views have to return strings.

flask_app.py
from flask import Flask

app = Flask(__name__)

@ app.route('/<multiply>/<int:num5>/<int:num5>')
def multiply(num5, num5)
 return '{} * {} = {}'. format (num5, num5, num5*num5)

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Erwan Mba Mba! I can see that you've put a good deal of effort into this, but a few things are going on here. First, you have some syntax errors. Namely, you're missing a colon : after the def multiply, and there is a space between @ and app. You may not have the space, and you must have the colon.

Secondly, you're doing a little more than they're asking you to right now. Right now, they want a route named multiply that takes no numbers and always returns the result of the multiplication of 5 times 5. So it's a little hard-coded at the moment, but you'll be building that out as you go through the challenge so that it'll be flexible. Also, it's just asking you to return "25" not "5 x 5 = 25". Remember that when these challenges are checking for strings, they must be exact matches.

from flask import Flask

app = Flask(__name__)

@app.route('/multiply')  # define the route
def multiply():  # define multiply with no parameters
    return '{}'.format(5*5)  # always returns 25 as a string

Hope this helps! :sparkles: