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?

How would I add the user username to the dictionary so that the username can be displayed on the logged in page?
You make session["username"]=username in checkLogin if login is successfull.

However. This is not a session. Session is a set of dictionaries that is present for each user (anonym or named), who are currently connected to your application. For example if you have more then one user, you have the same session data for all.

Maybe try:
https://github.com/linsomniac/bottlesession

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.