A session is similar to an object in a dictionary and is readable and writable.
It's a little different from cookies, and it's simple.
I'll just say a little bit about the change here.
1. Vim blog/views.py
If Uf.is_valid ():
Username = uf.cleaned_data[' username ']
Password = uf.cleaned_data[' password ']
Users = User.objects.filter (Username__exact=username,password__exact=password)
req.session[' username ') = Username Direct transfer
If users:
Response = Httpresponseredirect ('/index/')
Response.set_cookie (' username ', username,3600)
return response
Else
Return Httpresponseredirect ('/login/')
Else
UF = UserForm ()
Return Render_to_response (' login.html ', {' UF ': uf})
def index (req):
Username = req.session.get (' username ', ') landing on the page will have a session record
Return Render_to_response (' index.html ', {' username ': username})
def logout (req):
# response = HttpResponse (' logout ')
# Response.delete_cookie (' username ')
Del req.session[' username ') deleted directly,
return HttpResponse (' logout ok ')
Django Learning -17 Django Sessions session