Comments (3)
It looks like you are not inheriting from the HydraHeadApp base class, therefore your login app doesn't have access to the session_state. Please see the example login app at https://github.com/TangleSpace/hydralit-example/blob/main/apps/login_app.py.
This is an example of your app not being able to direct as it isn't able to set the session value that is accessed via the base class HydraHeadApp,imported from from hydralit import HydraHeadApp.
from hydralit.
hello @TangleSpace we already inherited HydraHeadApp base class and also followed similar process but we are struck at
AttributeError: 'LoginApp' object has no attribute 'session_state'
Traceback:
File "C:\Users\anaconda3\lib\site-packages\streamlit\script_runner.py", line 350, in _run_script
exec(code, module.dict)
File "C:\Users\Downloads\hydralit-example-main - Copy\hydralit-example-main\apps\login_app.py", line 166, in
c.run()
File "C:\Users\Downloads\hydralit-example-main - Copy\hydralit-example-main\apps\login_app.py", line 103, in run
self._do_login(form_data, c2)
File "C:\Users\Downloads\hydralit-example-main - Copy\hydralit-example-main\apps\login_app.py", line 132, in _do_login
self.set_access(form_data['access_level'], form_data['username'])
File "C:\Users\anaconda3\lib\site-packages\hydralit\app_template.py", line 54, in set_access
self.session_state.allow_access = allow_access
class LoginApp(HydraHeadApp):
"""
This is an example login application to be used to secure access within a HydraApp streamlit application.
This application implementation uses the allow_access session variable and uses the do_redirect method if the login check is successful.
"""
def __init__(self, title = '', **kwargs):
self.__dict__.update(kwargs)
self.title = title
def run(self) -> None:
"""
Application entry point.
"""
st.markdown("<h1 style='text-align: center;'>Secure Login</h1>", unsafe_allow_html=True)
c1,c2,c3 = st.columns([2,2,2])
#c3.image("./resources/lock.png",width=100,)
#c3.image("./resources/hydra.png",width=100,)
form_data = self._create_login_form(c2)
if form_data['submitted']:
self._do_login(form_data, c2)
def _create_login_form(self, parent_container) -> Dict:
login_form = parent_container.form(key="login_form")
form_state = {}
form_state['username'] = login_form.text_input('Username')
form_state['password'] = login_form.text_input('Password',type="password")
form_state['access_level'] = login_form.selectbox('Example Access Level',(1,2))
form_state['submitted'] = login_form.form_submit_button('Login')
return form_state
def _do_login(self, form_data, msg_container) -> None:
#access_level = login_data['access_level'] #Access denied!
access_level = self._check_login(form_data)
if access_level > 0:
msg_container.success(f"✔️ Login success")
with st.spinner("🤓 now redirecting to application...."):
time.sleep(1)
#access control uses an int value to allow for levels of permission that can be set for each user, this can then be checked within each app seperately.
self.set_access(form_data['access_level'], form_data['username'])
#Do the kick to the home page
self.do_redirect()
else:
self.session_state.allow_access = 0
self.session_state.current_user = None
msg_container.error(f"❌ Login unsuccessful, 😕 please check your username and password and try again.")
def _check_login(self, login_data) -> int:
#this method returns a value indicating the success of verifying the login details provided and the permission level, 1 for default access, 0 no access etc.
#view_all_users()
#user_result = view_all_users()
#clean_db = pd.DataFrame(user_result,columns=["Username","Password"])
#st.dataframe(clean_db)
db2postgres=Db2Postgres()
pwd=login_data['password']
hashed_pswd = db2postgres.make_hashes(pwd)
if (db2postgres.make_hashes(pwd) == hashed_pswd):
result = db2postgres.login_user(login_data['username'],hashed_pswd)
return 1
else:
return 0
'''
if login_data['username'] == 'joe' and login_data['password'] == 'joe':
return 1
else:
return 0
'''
if name == 'main':
c=LoginApp()
c.run()
from hydralit.
You can't just run the login app on it's own, it has to be a child of a HydraApp, look at the example again, line 37 , the login app is added to the parent. Also, you have to have another app to actually be kicked to. I suggest you study the example app again, as this is not how Hydralit works, if you want a single page application, you don't need Hydralit. https://github.com/TangleSpace/hydralit-example
from hydralit.
Related Issues (20)
- The api of streamlit.script_run_context api has changed HOT 5
- self.do_redirect does not change the menu option in the navbar HOT 5
- No module 'streamlit.script_run_context' HOT 7
- Switch apps when looping for realtime update HOT 1
- Set menu_items from page config HOT 1
- Demo on Heroku is down HOT 1
- hydralit 1.0.12 and streamlit 1.9.0 HOT 5
- How to disable the (huge) "Now Loading YOUR.APP" HOT 1
- Login and Logout through Hydralit! HOT 1
- Latest streamlit version not supported HOT 3
- The uploaded video file co-exists among different apps
- How to make navbar full-length of screen and placed all the way at the top? HOT 1
- type objct 'Server' has not attribute 'get_current' HOT 2
- Update for using `st.session_state` HOT 3
- Import Syntax Issues With Streamlit 1.12.2 HOT 4
- Error when running app.run() HOT 1
- Sites deployed on Heroku are not working
- Keyed widget values are lost when switching the pages HOT 1
- AttributeError: st.session_state has no attribute "allow_access". HOT 1
- When resizing navbar is cut off.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hydralit.