Function to generate radom alphanumeric cookies
If you are on python 3.6, you can just use the secrets module: which you should be using, in case the random value should be secret. 

From the documentation:

&gt;&gt;&gt; token_urlsafe(16)  
'Drmhze6EPcv0fN_81Bj-nA'


if you're below python 3.6, see here, how it's implemented. You  might just copy that.