In my app main folder, I have login.py in which on successful login, I am calling pages/main.py using st.switch_page(“./pages/main.py”). I have few other files under pages directory which I am showing in sidebar menu. This was working fine up and until today in Ubuntu 22, python - 3.11.8 and streamlit 1.32.2. I tried to set some page_config and I edited the login file and restarted the app. On successful login, the st.switch_page(“./pages/main.py”) did not work. So, I tried st.switch_page(“pages/main.py”), did not work and so I tried st.switch_page(“/pages/main.py”) and this also did not work. Now, I don’t know how to get this work. I upgraded to 1.33.0 and tried all the above and none of them worked. Can someone help me? How can i go to a lower version of streamlit, if required to get this work?
I tried st.page_link(label=“Main Page”, page=“/pages/main.py”), st.page_link(label=“Main Page”, page=“./pages/main.py”)…still getting the same StreamlitAPIException : Could not find page: /pages/main.py . Must be the file path relative to the main script, from the directory: App . Only the main app file and files in the pages/ directory are supported.
I faced to same issue unable to switch to pages which already exists. I try many ways
from streamlit import source_util
from streamlit.runtime.scriptrunner import get_script_run_ctx
ctx = get_script_run_ctx()
ctx_main_script = ""
if ctx:
ctx_main_script = ctx.main_script_path
page = "pages/overall.py"
st.write("**Main Script File**")
st.text(f"\"{ctx_main_script}\"")
st.write("**Current Working Directory**")
st.text(f"\"{os.getcwd()}\"")
st.write("**Normalized Current Working Directory**")
st.text(f"\"{os.path.normpath(os.getcwd())}\"")
st.write("**Main Script Path**")
main_script_path = os.path.join(os.getcwd(), ctx_main_script)
st.text(f"\"{main_script_path}\"")
st.write("**Main Script Directory**")
main_script_directory = os.path.dirname(main_script_path)
st.text(f"\"{main_script_directory}\"")
st.write("**Normalized Path**")
page = os.path.normpath(page)
st.text(f"\"{page}\"")
st.write("**Requested Page**")
requested_page = os.path.join(f"{main_script_directory}")
st.text(f"\"{requested_page}\"")
st.write("**All Pages Page**")
all_app_pages = list(source_util.get_pages(ctx_main_script).values())
st.json(all_app_pages, expanded=True)
in here only display main script page as all pages but i notice when rename and run the main script it provide pages but after try to login it gone so again error occurs.