I ran test view below (The 1st run):
# "my_app1/views.py"
from django.shortcuts import render
def test(request):
return render(request, 'index.html')
Then, I could set and get session in <script></script> in index.html as shown below (The 1st run):
{% "templates/index.html" %}
<script>
sessionStorage.setItem("test", "Hello");
console.log(sessionStorage.getItem('test')) // Hello
</script>
Next, I ran test view again with request.session.get('test') but I could not get the session as shown below (The 2nd run):
# "my_app1/views.py"
from django.shortcuts import render
def test(request):
print(request.session.get('test')) # None
return render(request, 'index.html')
Actually, I could get a Django template's JavaScript's cookie in test view.
So, how can I get the Django template's JavaScript's session in test view?