【发布时间】:2022-08-16 16:15:27
【问题描述】:
我是 python 和 streamlit 的新手。我正在尝试为我的应用程序创建一个登录过程。 但是当我尝试运行应用程序时,我收到以下错误。
with headerSection: AttributeError: __enter__
import streamlit as st
from user import login
headerSection = st.container
mainSection = st.container
loginSection = st.container
logoutSection = st.container
def main_page():
with mainSection:
st.text(\"Things to do\")
def loggedOut_clicked():
st.session_state[\'loggedIn\'] = False
def logout_page():
loginSection.empty();
with logoutSection:
st.button(\"Log out\", key=\"logout\", on_click=loggedOut_clicked)
def loggedIn_clicked(userName, password):
if login(userName, password):
st.session_state[\'loggedIn\'] = True
else:
st.session_state[\'loggedIn\'] = False
st.error(\"Invalid user name or password\")
def login_page():
with loginSection:
if st.session_state[\'loggedIn\'] == False:
userName = st.text_input(placeholder=\"Enter emailAddress\")
password = st.text_input(placeholder=\"Enter password\", type=\"password\")
st.button(\"Login\", on_click=loggedIn_clicked, args=(userName, password))
with headerSection:
st.title(\"Talent Search\")
if \'loggedIn\' not in st.session_state:
st.session_state[\'loggedIn\'] = False
login_page()
else:
if st.session_state[\'loggedIn\']:
logout_page()
main_page()
我使用 \'streamlit run app.py\' 来运行应用程序
谢谢
标签: python-3.x streamlit