Queueing system using Python Flask

So I’ve been trying to make a queueing system for an omegle clone.
Here, there is an empty “queue” dict. Whenever there is post request, i.e someone clicked on the CHAT button, one of 2 things can happen.

(1) If the queue dictionary is empty, create a random code, create a new item in queue, and save the info via sessions. After that, display a waiting screen (waiting.html). And check in a While loop if there are 2 members, in that case, redirect to /chat.

(2) If the queue dictionary is NOT empty, the code will be the first item in the dictionary’s key, which is a random 4 digit code, append your name in the member’s list of the item, and save all the stuff via sessions.
After that, if the number of members (len(members_list)) is 2, then redirect to /chat

Here’s the code:

#on submitting info / on post request / clicking on the chat button
        if len(queue) == 0:
            code = "".join(random.choices(ascii_uppercase, k=4))
            queue[code] = {"members" : [name]}

            session["name"] = name
            session["favColor"] = favColor
            session["code"] = code

            while len(queue[code]["members"]) == 1:
                return render_template("waiting.html")
            else:
                return redirect(url_for("chat"))
        
        else: 
            code = next(iter(queue))
            queue[code]["members"].append(name)

            session["name"] = name
            session["favColor"] = favColor
            session["code"] = code

            if len(queue[code]["members"]) == 2:
                return redirect(url_for("chat"))

First to check if the number of members are 2, I used an IF statement in the if len(queue) == 0: block.
Later when it didn’t work, i used the while loop. ITS STILL NOT WORKING