set cookies
Set the cookie using the set_cookie method in the response object
from django.http import HttpResponse
def set_cookie(request):
rsp = HttpResponse("set cookie")
rsp.set_cookie("set_cookie", "hello python", max_age=3600)
return rsp
Note: The response object refers to HttpResponseBase and all its subclasses
Call the above view method to view the set cookie
read cookie
All cookies are saved as a dictionary in COOKIES in the incoming request object
def get_cookie(request):
ck = request.COOKIES.get("set_cookie", '') # 若不存在set_cookie键,则返回空串
return HttpResponse(ck)
Call the above view method to view the read cookie
Source code and other data acquisition methods
Friends who want to get the source code, please like + comment + favorite , triple!
After three times in a row , I will send you private messages one by one in the comment area~