Reputation: 79
I am trying to add two numbers and display it in a new html page,
the code follows from flask import Flask,render_template,request
app=Flask(__name__)
@app.route('/')
@app.route('/<name>')
def index(name='Priya'):
name=request.args.get('name',name)
return "I am happy,{}".format(name)
@app.route('/add/<int:num1>/<float :num2>')
@app.route('/add/<float:num1>/<float :num2>')
@app.route('/add/<int:num1>/<int :num2>')
@app.route('/add/<float:num1>/<int :num2>')
def add(num1,num2):
#return str(num1+num2)
return """
<!doctype html>
<html>
<head><title>Addition game! </title></head><body>
<h1>
{}+{} = {}</body></html>""".format(num1,num2,num1+num2)
if __name__ == '__main__':
app.run(debug=True)
Upvotes: 6
Views: 10478
Reputation: 151
@app.route('/add/<int:num1>/<float :num2>')
contains a space which shouldn't be there
@app.route('/add/<int:num1>/<float:num2>')
is the correct syntax
Upvotes: 11