Hi there, new to Anvil and I’m following a tutorial but have hit an issue I can’t get around. Note that I’m using Python 3.
I’m importing a module into a form via:
from … import navigation (I know that Python 3 requires explicit imports)
In the form I have an init that is calling navigation.go_home()
But I keep getting the error:
AttributeError: ‘module’ object has no attribute ‘go_home’
But there is a attribute called ‘go_home’ in the module.
What am I doing wrong here?
Thanks,
Ed
Hello and welcome to the forum
happy to check your code, if you could share a clone link, so that we can find where the problem lies…
Check this for how to get the clone link and share the source code with us.
Welcome to the Q&A Forum!
Help each other by asking questions about Anvil, and answering other people’s.
Post each question as a new topic - and if someone helps you, don’t forget to say thank-you. Try to provide information to help people answer your questions:
Be specific about what you’re trying to do.
Be specific about what your problem is (eg what’s not working), and what you have already tried.
Include code samples if you can.
It often helps if you can share your app’s source code and …
Should mention that I changed it back to the python2 syntax of ‘import navigation’ on the version I cloned.
Change the import to :
from .. import navigation
That seems to work for me.
All new projects use python packages, and you need a relative path (which is back one from your form, hence the two dots).
The autocomplete is a big help - when you type "from " a list of visible imports is displayed for you to choose from. Most often you can select the rest of the import from there.
3 Likes
thanks, I’ve got it working now as I’ve switched to Chrome, I was using the new Edge browser which probably had something to do with it.
1 Like
I’ve hit the same problem again trying to import navigation into a different form and I can’t figure it out. Could you take another look? Check the AddMeasurementComponent, I have it with the ‘import … from navigation’ but it keeps saying ‘module’ object has no atribute ‘navigation’. I’ve tried it on both Chrome and Firefox with no change.
https://anvil.works/build#clone:DJMJAUYYOB5EJZYY=7D4SZOUP3XVC2BX7ISHR7KL3
Thanks
Actually don’t worry the exact same question was asked on a different thread.
If you want to be redirected to home after the user clicks “add measurement” you could do:
def button_save_click(self, **event_args):
.
.
.
# this gives you a reference to the main form
get_open_form().link_home_click()
I have not been able to import navigation inside your subform based on your setup for some reason (there might be an issue with circular imports , or a bug) but you should have access to its various functions via your main form.
If I had to guess I’d say that whe…
2 Likes
hey - you’re doing the circular import thing from this tutorial - which doesn’t work
great - was just gonna point you to that thread.
1 Like