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

mike henning
mike henning
1,384 Points

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

flask_app.py
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
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Hey 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 of int: or float:. (There are 4 combinations)
  • need default values for num1 and num2 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
mike henning
1,384 Points
from flask import Flask
app = Flask(__name__)

@app.route('/')
@app.route('/multiply<int:num1>/<num2>')
@app.route('/multiply<num1>/<int:num2>')
@app.route('/multiply<float:num1>/<num2>')
@app.route('/multiply<num1>/<float:num2>')

def multiply(num1, num2):
    return '{}'.format(num1*num2)
  1. I don't understand "route '/multiply' does not need trailing /" did that mean to take out the / after all my @app.route('/multiply ???

2.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.

  1. I'm feeling really disconnected to the lesson.. I don't remember where we talk about multiply and making default values. I tried using what I learned in ADDING but there was nothing about making default values.
Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points
  • You need 6 routes: ‘/‘, ‘/multiply’, and the four combinations of ‘/multiply/...’ with the various ints and floats.
  • the default values are for the function parameter definition. The are covered in Basic Python and is a prerequisite for the Flask course.

Hope this helps

mike henning
mike henning
1,384 Points

now that im looking at i havent started the basic python i dont know how i pass that. thank you