Previously, I only have username and password, so I make it
from this:
VALID_USERNAME_PASSWORD = {"abc": "abc", "welcome": "world"}
to this:
VALID_USERNAME_PASSWORD_PAIRS = df_userpwd.set_index('username')['password'].to_dict()
Currently, I have a list of username with password and role.
VALID_USERNAME_PASSWORD = {"test": {"password":"test", "role":"admin"}, "hello": {"password":"world", "role":"user"}}
So, if all the information is store in dataframe, how can I extract it from csv?
Due to my app.py has .get
function, therefore, the below solution is workable for me:
pwd.csv
username | password | role |
---|---|---|
test | test | admin |
hello | world | user |
code:
VALID_USERNAME_PASSWORD= pd.read_csv("pwd.csv").set_index('username').transpose().to_dict()
>>> {"test": {"password":"test", "role":"admin"}, "hello": {"password":"world", "role":"user"}}