当cookie值包含中文是,Django无法执行response.set_cookie
,在服务器控制台报错:
AttributeError:'NoneType'object has no attribute 'split'
解决办法:使用Json
import json
defcookieTest2(request):
response = HttpResponse("OK")
if 'h1' in request.COOKIES:
h1 = request.COOKIES['h1']
response.write('<h1>' +json.loads(h1) + '</h1>')
response.set_cookie("h1",json.dumps("我是COOKIE"))
return response