我正在尝试制作一个简单的Bottle Web应用程序,该应用程序具有一个简单的函数,该函数接受两个参数(两个整数)并返回两个整数的和,但将它们连接起来。我是新手。这是代码:
from bottle import run, get
@get('/')
def docs():
return {'<h1> Calculator </h1>'}
@get('/calc/<x>/<y>')
def add(x,y):
return x + y
run(reloader=True, debug=True)
默认情况下,路径参数中的Bottle返回字符串。您必须将字符串转换为整数对象。瓶子可以帮你做。
尝试一下:
@get('/calc/<x:int>/<y:int>')
def add(x,y):
return x + y