I am using this code to add two numbers
import webapp2
class HomeHandler(webapp2.RequestHandler):
def get(self):
self.response.write('This is the HomeHandler.')
class AddHandler(webapp2.RequestHandler):
def get(self, num1, num2):
num3 = int(num2)+int(num1)
self.response.write('The sum of the numbers is- %d' % num3)
app = webapp2.WSGIApplication([
webapp2.Route(r'/', handler=HomeHandler, name='home'),
webapp2.Route(r'/add/<num1:\d+>/<num2:\d+>',
handler=AddHandler, name='add')
], debug=True, config=config)
# app.router.add((r'/add/<num1:\d+>/<num2:\d+>', handler=AddHandler, name='add'))
print(app)
# app = webapp2.WSGIApplication([
# (r'/', HomeHandler),
# (r'/products', ProductListHandler),
# (r'/products/(\d+)', ProductHandler),
# ])
def main():
from paste import httpserver
httpserver.serve(app, host='127.0.0.1', port='8080')
if __name__ == '__main__':
main()
I am using this url to add the two numbers http://127.0.0.1:8080/add/3/4
but i want all the inputs to be after single / ex- http://127.0.0.1:8080/divide/a=3&b=3
And after taking the input i have to cast them to integer to add them and is this possible without casting?
How to do this please help?