Is it posible to read a cookie in a template tag?
I set the cookie in a middleware but I'd like to read in a template tag.
def process_response(self, request, response):
response.set_cookie('changed', 'yes')
response.set_cookie('choose', request.LANGUAGE_CODE)
return response
Thanks
Since cookies are key/value pairs, you can read the value of a cookie in a template using the dot notation as shown below.
In your views:
def process_response(self, request, response):
response.set_cookie('changed', 'yes')
response.set_cookie('choose', request.LANGUAGE_CODE)
return response
And in your template:
{{ request.COOKIES.cookie_name }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With