What I’m trying to do:
I’m trying to build a navigation client module just like in the course By Michael Kennedy. The course is titled Anvil: Web Apps With Nothing but Python. Chapter 4 discusses Refactoring Navigation.
What I’ve tried and what’s not working:
I’m trying to import the navigation client module into a start up form. I have followed Kennedy’s steps but I keep on getting the following error:
ModuleNotFoundError: No module named ‘navigation’
Code Sample:
in the Startup Form
import navigation
in the navigation Client Module
from HomeAndNonComponent import HomeAndNonComponent
from Account import Account
from Compare import Compare
from HomeDetails import HomeDetails
from SetHeight import SetHeight
# Navigation must have access to HomeForm
home_form = None
def get_form():
if home_form is None:
raise Exception("must set the home form")
return home_form
def go_Add():
form = get_form()
self.load_component(AddMeasurement())
def go_Home():
form = get_form()
self.load_component(HomeAndNonComponent())
def go_Compare():
form = get_form()
self.load_component(Compare())
def go_Account():
form = get_form()
self.load_component(Account())```
**Clone link:**
*share a copy of your app*
Welcome to the forum!
The Anvil autocompleter is your friend with imports. Start typing from .nav
and see what comes up. It’ll generally find the right module you want to import and give you some options.
The course you’re following is probably a pretty old one, done before some fairly major changes to Anvil’s package structure, which is why the imports it shows doesn’t work. Trust the autocompleter to know what currently works.
Thank you so much for your help. I used from …navigation and it found …navigation but when I complete it with import * it still fails.
If I do import navigation I still get the error even though from …n finds navigator
To match the previous import navigation
you want the from .. import navigation
form of import. Then the code in the startup form should be the same, using navigation.
to access elements of the navigation module.
Thank you so much for your help. Yep that worked. Other problems I’m having is likely due to following a course that’s old.
Can you recommend a newer course that utilizes the newer version of Anvil? Really impressed by what I’ve seen and would really like to pursue this. Thanks again for your help.
Honestly, Anvil changes quickly enough that most Anvil courses are probably incorrect in some manner or another as soon as they’re published. That’s a good thing in the sense that Anvil’s always being updated, always getting new features, but it makes any reference material but the official docs hard to keep updated.
If you like the course you’re following, keep going with it but understand that some things won’t work as is, and you’ll need to ask on the forums to get past those parts.
You can also search through the forum, I know others have posted links to Anvil courses. I personally am the “dive in and work through the issues” sort of developer, so can’t say which of them might be best.
Understood. Thank you so much for the feedback. Much appreciated.