Flask session variables

后端 未结 3 1684
眼角桃花
眼角桃花 2021-02-03 15:31

I\'m writing a small web app with flask. I have a problem with session variables when two users (under the same network) try to use app.

This is the code:



        
3条回答
  •  迷失自我
    2021-02-03 15:41

    Using randint(0,4) to generate number means that they will sometimes be equal for different users. To generate unique number every time use uuid:

    from uuid import uuid4
    def random():
        session['number'] = str(uuid4())
        return None
    

    or generator:

    import itertools
    consequent_integers = itertools.count()
    
    def random():
        session['number'] = consequent_integers.next()
        return None
    

提交回复
热议问题