I'm pretty new to coding with Python and I am trying to save a users username in a session variable which should be a new entry in the session dictionary. The code I have is
from bottle import route, request, debug, run, template
session={'logins':0}
def checkLogin(name,password):
if name==password:
return True
else:
return False
@route('/')
def welcome():
return template('welcome.tpl')
@route('/login')
def login_form():
return template ('login.tpl')
@route('/checkLogin', method='post')
def login_submit():
global session
name = request.forms.get('name')
password = request.forms.get('password')
if checkLogin(name, password):
session['logins']=session['logins']+1
return template('loggedIn2.tpl',message='Successfully logged in!',success=True,logins=session['logins'])
else:
return template('loggedIn2.tpl',message='Unlucky! Try again.',success=False)
@route('/logout')
def logout():
return template ('login.tpl')
debug(True)
run(reloader=True)
How would I add the user username to the dictionary so that the username can be displayed on the logged in page?