Streamlit did not show the imput box show blank screen

dear boss

Please review the code I obtained from the internet. It did not produce any errors; however, it does not display the input box for the username and password, resulting in a blank screen. Kindly examine the code and provide an appropriate solution.

import streamlit as st

Simulate login status

if “logged_in” not in st.session_state:
st.session_state[“logged_in”] = False

def login_page():
st.title(“Login”)
username = st.text_input(“Username”)
password = st.text_input(“Password”, type=“password”)
if st.button(“Login”):
if username == “u” and password == “p”:
st.session_state[“logged_in”] = True
st.success(“Logged in successfully!”)
st.rerun()
else:
st.error(“Invalid credentials.”)

def dashboard_page():
st.title(“Dashboard”)
st.write(“Welcome to your dashboard!”)

def admin_page():
st.title(“Admin Panel”)
st.write(“Admin-only content.”)

pages = [
st.Page(login_page, title=“Login”),
]

if st.session_state[“logged_in”]:

pages.append(st.Page(dashboard_page, title="Dashboard"))
# Conditionally add admin page
if st.session_state.get("is_admin"): # Assuming you set this after login
    pages.append(st.Page(admin_page, title="Admin"))

st.navigation(pages)

Hi @badar, welcome to the forum!

Can you please edit your post so that the code is all in a code block, so that it’s readable? You can put a line with ``` above and below your code to do that.

If I’m reading your code correctly, the only piece you’re missing is this

current_page = st.navigation(pages)

current_page.run()

You have to actually call .run() on the output of st.navigation, or it won’t actually run the currently-selected page.

Thank you for your assistance, sir. With your help, the application is now functioning and displaying the user and password text boxes. However, I have added some code to facilitate access for other users, but it has not produced the desired results. I would appreciate it if you could provide the correct code to ensure that all users can view and access their designated pages.

see my code


import streamlit as st
username =''
password = ''
if 'logged_in' not in st.session_state:
   st.session_state['logged_in'] = False

def login_page():
   st.title('Login')
   username = st.text_input('Username')
   password = st.text_input('Password', type='password')
   if st.button('Login'):
       if username == 'u' and password == 'p':
           st.session_state['logged_in'] = True
           st.header('Muhammad is the best')
           st.success('Logged in successfully!')
           st.rerun()
       elif username == 'o' and password == 'p':
           st.session_state['logged_in'] = True
           st.header('Muhammad is the best')
           st.success('Logged in successfully!')
           st.rerun()
       else:
           st.error('Invalid credentials.')

def dashboard_page():
   st.title('Dashboard')
   st.write('Welcome to your dashboard!')

def dashboard_page111():
   st.title('Tesing page  d')
   st.write('testing page =============!')

def admin_page():
   st.title('Admin Panel')
   st.write('Admin-only content.')

pages = [
st.Page(login_page, title='Login'),
]

if st.session_state['logged_in']:
   if username == 'u' and password == 'p':
       pages.append(st.Page(dashboard_page, title='Dashboard'))
   elif username == 'o' and password == 'p':
       pages.append(st.Page(dashboard_page111, title='Dashboard'))
# Conditionally add admin page
   if st.session_state.get('is_admin'): # Assuming you set this after login
       pages.append(st.Page(admin_page, title='Admin'))


current_page = st.navigation(pages)
current_page.run()