I am building an app using Web2py framework... I don't want to have to use the request object to get all of the querystring parameters, instead I'd like to build my controller with named parameters and have the router unpack the querystring (or form data) dictionary into the named parameters and call my controller.
so instead of a controller method of
create_user():
where I would use the global request() object and look through the vars list... I would prefer instead to have
create_user(first_name, last_name, email):
like I see in other MVC platforms.
is this possible in Web2py already? or is there a plugin for it? or do I need to add that myself?
No. As stated in the book, an URL of the form
http://127.0.0.1:8000/a/c/f.html/x/y/z?p=1&q=2
maps to application (folder) a
, controller (file) c.py
, function f
, and the additional arguments must be unpacked from the request object as
x, y, z = tuple(request.args)
p = request.vars['p'] # p=1
q = request.vars['q'] # q=2
Furthermore, web2py specifically detects valid controller functions as those functions that have no arguments. AFAICR, this is opposite to Django which detects valid controller functions as those that have at least one argument.