cookies and session

Set our cookies

def set_cookies(request):

  Get the information sent by the postman

  request refers to a request for information http

  GET method is to get in the way we get the request data

  The latter name is our key value inside the distal end, in front of the name is the variable in the received data we django

  name=request.GET.get('name')

  Http assigned to instantiate a coo

  coo = HttpResponse ( 'I set operation cookies')

  Set cookies

  coo.set_cookies('cooke_name',name)

  return coo

  Get our cookies

def get_cookies(request):

  The front end to get the information we pass over

  request refers to information http request

  doing=request.GET.get('doing') 

  COOKIES is the way we get the data in the manner requested

  name=request.COOKIES.get('cooke_name')

  cooke_name we django which variables receive data

  return HttpResponse(name+doing) 

 

 

Set session

def set_session(request):

  name=request.GET.get('name')

  Obtaining session

  request.session['session_name']=name

  return HttpResponse ( 'This is a process of setting the session')

 

def get_session(request):

  doing=request.GET.get('doing')

  name=request.session.get('session_name')

  return HttpResponse(name+doing)

 

 

cookies, session role : to maintain user state, telling the server who you are.
 
The difference migrate command and makemigrations : makemigrations generate migration file, migrate to perform the migration file
 
cookies : to consider important information in the cookies are put at each exchange
1. Setting the cookie :
Get value
Set to cookies
Returning to the front
2. Inspection cookies
 
cookies, session action holding state of the user:
 
orm: python operation of the database environment
Advantages : improved, reducing the learning curve programmers
Disadvantage : very slow execution rate
 
The contents of the database written in models.py
 
Generate migrate files: python manage.py makemigrations
 
get and post similarities and differences:

Transfer methods : get transmitted through the address bar, it is transmitted in clear text, insecurity, post packet transmission. Security is relatively high.

Transport length: get parameters length limit (limited by the url length), and post unlimited

GET and there is a significant difference between the POST, simply say:

GET generates a TCP packet; generating the POST two TCP packets

  

Guess you like

Origin www.cnblogs.com/fado7/p/12072165.html