Session variables in Django are small pieces of information that the website remembers about you while you use it. They keep track of your choices and settings temporarily until you leave the website. Once you come back or refresh the page, the session variables start anew.


Example:

 # Adding session variable (collecting coins):
def collect_coins(request):
    if 'coins' in request.session:
        request.session['coins'] += 10  # If coins already exist in session, add 10 more
    else:
        request.session['coins'] = 10  # If it's the first time, set coins to 10

# Removing session variable (spending coins):
def spend_coins(request):
    if 'coins' in request.session:
        if request.session['coins'] >= 5:  # Check if you have enough coins to spend
            request.session['coins'] -= 5  # If yes, spend 5 coins
        else:
            del request.session['coins']  # If not enough coins, remove the 'coins' session variable