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

Khoa Nguyen
Khoa Nguyen
1,781 Points

I don't understand this question

can you explain a little bit about this question

flask_app.py
from flask import Flask

app = Flask(__name__)

@app.route('/multiply')
@app.route('/multiply/<int:var1>/<int:var2>')
@app.route('/multiply/<float:var1>/<float:var2>')
@app.route('/multiply/<int:var1>/<float:var2>')
@app.route('/multiply/<float:var1>/<int:var2>')
def multiply(var1=5, var2=5):
  response = var1 * var2
  return str(response)

1 Answer

Hi Khoa

The question or challenge wants you to create a view called multiply that will accept and return the product of the two values.

from flask import Flask

app = Flask(__name__)

@app.route('/multiply')
@app.route('/multiply/<int:var1>/<int:var2>') # to handel a querystring like so  /multiply/5/5
@app.route('/multiply/<float:var1>/<float:var2>')# to handel a querystring like so /multiply/1.5/1.5
@app.route('/multiply/<int:var1>/<float:var2>')# to handel a querystring like so  /multiply/5/1.5
@app.route('/multiply/<float:var1>/<int:var2>')# to handel a querystring like so  /multiply/1.5/5
def multiply(var1=5, var2=5): # setting a default for each variable
  response = var1 * var2
  return str(response)

hope this helps