I will talk about Java but it shall be similar in django. Session attributes are accesible in servlets and jsp in similar way like request parameters. You can look at it like server side stored request parameters. Some frameworks like JSF even use request scope to store session variable. So basicly you can look at session as request decorator which puts value stored in web container.
why cookie is set in response but session in request?
Domanda
I know how session
and cookies
work. I am doing an online course on django
where a function for setting language preference in session
and cookie
is written in views.py
. I do not understand why cookie
is set on response
but session
on request
. The instructor mentioned it works the same in PHP
or any other web framework
.
but he did not explain why? can some one explain why?
Here is the function:
def language(request,language=“en-us”):
response=HttpResonse(“setting language to %s” %language)
response.set_cookie(‘lang’,language)
request.session[‘lang’]=language
return response
Nessuna soluzione corretta
Altri suggerimenti
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow