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 trialmike henning
1,384 PointsI'm still confused
from flask import Flask
app = Flask(__name__)
app = Flask(_multiply_)
@app.route('/')
@app.route('/multiply/<num1>/<num2>')
@app.route('/multiply/<int:num1>/<num2>')
@app.route('/multiply/<num1>/<int:num2>')
@app.route('/multiply/<int:num1>/<int:num2>')
@app.route('/multiply/<float:num1>/<float:num2>')
@app.route('/multiply/<float:num1>/<num2>')
@app.route('/multiply/<num1>/<float:num2>')
def multiply(num1,num2):
return '{}' .format(num1*num2)
I'm getting an error : NameError: name 'multiply' is not defined
and also I don't understand how to make default values
from flask import Flask
app = Flask(__name__)
app = Flask(_multiply_)
@app.route('/')
@app.route('/multiply/<num1>/<num2>')
@app.route('/multiply/<int:num1>/<num2>')
@app.route('/multiply/<num1>/<int:num2>')
@app.route('/multiply/<int:num1>/<int:num2>')
@app.route('/multiply/<float:num1>/<float:num2>')
@app.route('/multiply/<float:num1>/<num2>')
@app.route('/multiply/<num1>/<float:num2>')
def multiply(num1,num2):
return '{}' .format(num1*num2)
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsHey mike henning, you have all the parts, but they need some adjusting.
- remove the line
app = Flask(_multiply_)
- route
'/multiply'
does not need trailing / - the unqualified route
'/multiply/<num1>/<num2>'
will match everything making the subsequent routes ignored. Make sure all “num” variables in routes use one ofint:
orfloat:
. (There are 4 combinations) - need default values for
num1
andnum2
since the’/multiply’ route does not specify those parameters:
(num1=5, num2=5)` - remove blank line between decorators and function definition
- remove space before
.format
method
Post back if you need more help. Good luck!!!
mike henning
1,384 Pointsnow that im looking at i havent started the basic python i dont know how i pass that. thank you
mike henning
1,384 Pointsmike henning
1,384 Points2.im still confused "need default values for num1 and num2 since the ’/multiply’ route does not specify those parameters:(num1=5, num2=5)`" do I need to add a route that makes a default values (num1=5, num2=5).. I know we didn't cover parameters in flask so I don't how to make that connection.
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsHope this helps