Create a new page on click of submit

Hi All,

I am creating a new app to insert student records, from my main app page( I insert records in to database. Using multipage concept I have created and under /pages/ folder to search and delete records.

Upon clicking “Insert” in I intend to display the new records inserted in to database in a new page.

To achieve this I created a new in the same folder as and tried to do st.switch_page(“”) which gives me below error:

streamlit.errors.StreamlitAPIException: Could not find page:
C:\Users\SK\Desktop\python\ Must be the file path relative to the main script, from the directory: python. Only the main app file and files in the pages/ directory are supported.

To encounter this I placed the under /pages , this absolutely works fine to switch page but the “View Record” also gets listed in the side bar which I dont want.

I also tried hide this page using st_pages but unfortunately streamlit cannot switch to a page which is hidden.

Any pointers on how to achieve this? How would I launch a new page to display the record I inserted into DB by clicking “insert” button.

  1. Streamlit has an option to conditionally display sidebar links.
    You do this by running streamlit with the option to disable the sidebar rendering. Depending on the version of streamlit, the option name changes. In latest version of streamlit the option is client.showSidebarNavigation
    You can then use “st.page_link” inside “with st.sidebar” as you see fit in the page.
    Check this: Create custom navigation menus - Streamlit Docs

  2. Have you tried “switch_page” link with a “./” prefix perhaps? I dont know but worth a try…

1 Like

Here’s an example that works just fine, if client.showSidebarNavigation is set to false

import streamlit as st
from pathlib import Path

for page in Path("pages").iterdir():
    left, right = st.columns(2)
    if left.button("Switch to " +
    if right.button("Delete " +

page_name = st.text_input("Page name")
if st.button("Add new page"):
    Path("pages", f"{page_name}.py").touch()


showSidebarNavigation = false

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