Daily mining pit, cookie can not save Chinese string solutions ...

Description: broadsword Guan Gong is not afraid, afraid of a sudden the foot of the pit, crooked legs ...

A cookie can not save Chinese string remember! ! ! ! !

solution?

Option One:

The Chinese character string encoded into base64, take time and then decoded, as follows ...

Import Base64 
        
    # when storing encoded 
      UN = base64.b64encode (uname.encode ( ' UTF-. 8 ' ))    # Chinese can not be stored in a cookie, the coding process needs to 
      response.set_cookie ( ' the uname ' , UN)   # stored in a cookie the user name in 

    # acquiring decoding 
     the uname = request.COOKIES.get ( ' the uname ' , '' ) 
     the uname = base64.b64decode (the uname) .decode ()   # Base64 decoding

 

Option II:

The Chinese string saved in a dictionary, and then a string serialization, you can take the final browser

#
trans_uname=json.dumps(username)
response.set_cookie('username',trans_uname)
#
username=request.COOKIES.get('username')

 

Guess you like

Origin www.cnblogs.com/jum-bolg/p/12563662.html