【问题标题】:with headerSection: AttributeError: __enter__带有 headerSection: AttributeError: __enter__
【发布时间】: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


    【解决方案1】:

    因为您的 st.container 缺少括号(), 你需要添加()到你的容器st.container()

    headerSection = st.container()  # Add () to st.container
    mainSection = st.container()  # Add () to st.container
    loginSection = st.container()  # Add () to st.container
    logoutSection = st.container()  # Add () to st.container
    

    【讨论】:

      猜你喜欢
      • 2018-02-26
      • 1970-01-01
      • 2019-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多