Pass vars to request handler

Hi,

I simply want to pass an argument, called regform from within a html template to my plugin controller __init__.py via:

            <a href="{{url_for('plugin_example.transmitRegform', regform )}}" class="i-button icon-plus">

in __init__.py the url rule is defined by:
blueprint.add_url_rule('/test', 'transmitRegform', view_func=RHTransmitRegform)

Within the request handler class RHTransmitRegform, there is a method called _process. Now, I do not know, how to access the variable regform within that method.
Any ideas ?

regards,

Phil

if it’s in the query string, you can get it from request.args (it’s pretty much like a dict - please see the flask docs for details though).

Hi ThiefMaster,

do you mean to use the method request.args() within the _process method of the RH object ? like the following:

class RHTransmitRegform(RH):
def _process(self,*args,**kwargs):
myVar = request.args()
...

In my case, this does not work. Can you give a minimal example of the usage of request.args ?

Remove ,*args,**kwargs from _process; it’s never called with arguments so accepting starargs/kwargs doesn’t do anything useful.

If the URL is /test?registration_form_id=123, then you’d get the ID using request.args['registration_form_id']. This will automatically fail with a 400 error if the param is not provided. You can use .get() instead of [] to get None instead of failing.

BTW, depending on what you are doing, you might want to put it in the URL itself like it’s done for most cases in Indico itself, i.e. /test/123. To do that you’d use /test/<int:registration_form_id> in the blueprint; the value will then be in request.view_args.

Hey ThiefMaster,

It finally worked with request.args['reg_form_id']. Thank you for your help.

Best regards,

Philipp