问题
On my login script it creates a cookie for the user logging in of their email address and password. Problem I am having is when the email address is set it puts the entire email address between double quotes. How would I get it to not?
if request.method == 'POST':
post = request.POST
email = post.get('email', None)
response.set_cookie('emailaddress', email, max_age=expire_v)
回答1:
You can try strip method
email.strip('"')
回答2:
Another solution for this issue is to directly work with a SimpleCookie object and attach it to your response
>>> from Cookie import SimpleCookie
>>> mycookie = SimpleCookie()
>>> mycookie['emailaddress'] = 'josuebrunel@gmail.com'
>>> mycookie['emailaddress']['expires'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
>>> print(mycookie)
Set-Cookie: emailaddress="josuebrunel@gmail.com"; expires=2015-11-25 22:20:16
>>> response.cookies = mycookies
I had the same issue, and i fixed by using SimpleCookie
来源:https://stackoverflow.com/questions/7992603/django-cookies-place-double-quotes-around-email-address