Secondary pages wont load

My public app won’t load secondary pages. My main page loads and runs just fine, but when I try to go to other pages using the navigation sidebar or st.switch_page, the link says ive gone to that page, but the page never loads. My app has been up for a while and im only now seeing this issue. I havent made any code changes recently, so this is happening out of no where. Also it is happening on my deployed app and my local app. Any help would be great, thank you!
https://home-workout-generator.streamlit.app/
Heres my log as well. Nothing out of the ordinary.

Hi @Cameron, welcome to the forum!

My best guess is that the issue is because you are importing the home page import Workout_Generator from all of the sub-pages.

I assume you are doing that to have a common background, etc. But, importing the home page will actually also run all of the code in it.

There are two options I would recommend trying to fix this:

  1. [preferred] Create a common.py that has important utility code like the Background function, and import those in each of your page from common import Background, InitializeLogin, etc.
  2. Alternatively, change Workout_Generator so that everything is defined inside a function, including the code that actually generates the UI for the home page. You could call that def main() and then at the bottom of your app, do
if __name__ = '__main__': 
    main()

This will make it so that importing Workout_Generator doesn’t actually run the main page of your app, it just defines the various functions.

I’m not 100% sure that’s the issue, but that’s my best gueess.

Thank you! This worked. Not sure why this problem appeared out of now where after it worked for weeks and I hadn’t made any changes in that time.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.