-2

This code gives me a KeyError: 'name', at if(name != session["name"]). If it's needed, followers is a dictionary with a string key and a list item. If someone could help me fix this that would be great.

    if(request.method == "GET"):
        try:
            return render_template("user.html", name=name, bio=accounts[name]["bio"], follower=len(followers[name]))
        except:
            return "incorrect username, <a href=/users>go back</a>."
    else:
        print(name)
        if(name != session["name"]):
            if(session["name"] not in followers[name]):
                followers[name].append(session["name"])
            else:
                followers[name].remove(session["name"])
        f = open("database_followers.json", "w")
        f.write(json.dumps(followers))
        return redirect(f'/users/{name}')```

1 Answers1

0

I think you need to check what is it in the variable, session. It is giving error since it can not find the key "name" in session.

Onur Odabaşı
  • 306
  • 1
  • 4