I have a login streamlit page and after a succesful login I do
if not check_password():
but then I get this error
streamlit.errors.StreamlitAPIException: Could not find page: 'other_pages/app.py'. Must be the file path relative to the main script, from the directory: ai-portal.
even though I have the path correct. I tried with renaming the folder pages and then it works but then I get a list of the pages in the sidebar and the user can freely move from one to the other without login in like this:
I’m in Linux. If I put the app.py file in the pages folder then it works fine and it finds the file with no problem. But if I change the name of the folder to, say, other_pages and then I use the same path but with other_pages like other_pages/app.py then it throws me the error.
I would have no problem using the pages/app.py path but the issue is that when I use that path, streamlit put the list of the pages on the sidebar to navigate to and the user can freely go from one page to the other so the login page becomes a moot point.
Only Python files structured in compliance with Streamlit’s multipage structure will work. (Your main file, and one in a
pages/ folder relative to your main file.) So this is expected.
From the docs:
When st.switch_page is called, the current page execution stops and the specified page runs as if the user clicked on it in the sidebar navigation. The specified page must be recognized by Streamlit’s multipage architecture (your main Python file or a Python file in a pages/ folder). Arbitrary Python scripts cannot be passed to st.switch_page.
I can look at rearranging the text in the docs to call out the warning in the parameter description if that might be clearer…
To hide the default navigation, use the configuration option,
showSidebarNavigation=false. This tutorial goes over an example.
Thank you so much! Hiding the sidebar navigation did the trick for me!
I think the error message in the case of using switch_page with code outside the pages folder could be more descriptive because right now it makes it seem that it’s a path formatting issue but it’s actually a path restriction issue.
Good suggestion. I’ve passed your comment to the team for
Seeing how easy it will be to improve the error text!
We’re also working on removing the restriction on only files in the
pages/ folder and allowing multi-page apps to use other files
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.