1

I am using js.cookie CDN to get cookie .In my browser there is a Cookie with name sessionid ,(set by django backend itself) ,having some value , but

Cookie.get('sessionid') is giving undefined 
//CDN : <script src="https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js"></script>

sessionid in Cookie

2 Answers2

3

You can not get value of that cookie (sessionid) because it has set HttpOnly to true. That means, that cookie is only received and send through http, but is not accessible by javascript. That is for security reason to prevent stealing session.

If you really need this, maybe you can change the HttpOnly setting on server side - somewhere in django, or write it on page and then access it with jquery. But that would compromise security.

Márius Rak
  • 1,356
  • 2
  • 15
  • 35
1

in Django you can get the session_id by using => request.session.session_key . You are new to SO, check the older questions it is easier.

In Django, how can I find out the request.session sessionid and use it as a variable?

since we sending on client side ,In django we can also set a key in settings.py

SESSION_COOKIE_HTTPONLY = False 
ytsejam
  • 3,291
  • 7
  • 39
  • 69