Hi there,
I am learning the HashRouting but I encournter the following problem:
I am trying to use routing.set_url_hash to point to my Form1, which as an argument ‘items’.
In the MainForm that calls the Form1, I have the following code:
routing.set_url_hash(‘form1’)
In the Form1 that was being called by the MainForm, I have the following code:
@routing.route(‘form1’)
Class Form1(Form1Template):
def init(self, items, **properties):
When the MainForm runs, I have the following error:
TypeError: init() missing 1 required argument: ‘items’
I have an ‘items’ object (from the MainForm) that I want to pass into the ‘Form1’, but I don’t know how to do it with routing.set_url_hash. Does anyone know?
routing.set_url_hash* cocumentation:
https://anvil-extras.readthedocs.io/en/latest/guides/modules/routing.html#api
One way to do it is to initialize a property in form1 corresponding to the name of the object you’re passing to it like so:
@routing.route("form1")
class Form1(Form1Template):
def __init__(self, data=None, **properties):
if data:
self.items = data
With the above setup, you can then navigate to Form1 and pass the items data to it like so:
routing.set_url_hash("form1", data=items) # note the use of data as extra arguement
According to the documentation, providing the data argument to routing.set_url_hash
will pass data property to form1. But Form1 should have been prepared to receive this data property by initializing it accordingly as was done above.
1 Like
I don’t use extra arguments on forms loaded by the routing
module. Using extra arguments kind of defeats the purpose of using the routing
module.
I pass all the arguments on the URL, then I use self.url_dict['items']
.
1 Like