This code creates and adds methods to a class:
def add_controller(self, cls, i, return_url):
@http.route(return_url, type="http", auth="public", website=True) # Very important, missing!
def innercontroller(self, **kw):
print("Helloo here with ID: " + i)
innercontroller.__name__ = "controller_html_form_id_" + i # Name of the new method
setattr(cls, innercontroller.__name__, innercontroller)
print("Done")
def create(self):
self.add_controller(HtmlFormController, i, return_url)
The code works fine and the method is generated, but unfortunately without the decorator.
I want to create multiple methods with different return_url
, meaning that every decorator will be different.
EDIT:
In the end, I want to have a method like this:
@http.route("/custom13", type="http", auth="public", website=True)
def controller_html_form_id_13(slef, **kw):
return "Example method!"
So then when the user calls the route example.com/custom13
, then he should see Example method!
in his browser.
The only thing missing is the decorator @http.route(...)
How can I add this decorator to the generated method?