Questions tagged [django-cookies]

17 questions
155
votes
6 answers

How to set and get cookies in Django?

I have a web site which shows different content based on a location the visitor chooses. e.g: User enters in 55812 as the zip. I know what city and area lat/long. that is and give them their content pertinent to that area. My question is how can I…
Jeffrey
  • 1,621
  • 2
  • 12
  • 7
125
votes
26 answers

Django CSRF Cookie Not Set

I have some problem for a while now, I'm experiencing CSRF Cookie not set. Please look at the code below: views.py: def deposit(request, account_num): if request.method == 'POST': account = get_object_or_404(account_info,…
user2389182
32
votes
3 answers

How to delete cookies in Django?

I'm trying to develop login page for a web site. I stored users which logged on correctly to a cookie with set_cookie. But I don't know how to delete the cookie. So, how can I delete the cookie to make a user log out?
Nick Dong
  • 3,638
  • 8
  • 47
  • 84
28
votes
6 answers

How to set cookie and render template in Django?

I want to set a cookie inside a view and then have that view render a template. As I understand it, this is the way to set a cookie: def index(request): response = HttpResponse('blah') response.set_cookie('id', 1) return…
Jim
  • 13,430
  • 26
  • 104
  • 155
9
votes
4 answers

Django does not delete cookie

I have a site running Django 1.6 using a custom authentication backend (CoSign). Authentication works, but to log out I need to delete a cookie. This is the cookie before logging out, using Firebug: Name: cookie_name Domain: cookie_domain Path:…
tao_oat
  • 1,011
  • 1
  • 15
  • 33
4
votes
2 answers

session.get_expiry_age() never decreases

I set SESSION_COOKIE_AGE to some value in my settings.py and I want to retrieve the time that is left before a session dies by using session.get_expiry_age() from a view. However, it seems the returned value is never changing between different calls…
Buddyshot
  • 1,614
  • 1
  • 17
  • 44
1
vote
1 answer

response.set_cookie() vs response.cookies[] in Django

I could set the cookies with response.set_cookie() and response.cookies[] as shown below. *I use Django 4.2.1: # "my_app1/views.py" from django.http import HttpResponse def test(request): response = HttpResponse('Test') …
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
1
vote
2 answers

Why don't cookies work properly in Django?

I have to set cookies to save cart details in my project but its not working, when i test cookies using function request.session.set_test_cookie() Then it set cookies but response.set_cookie function is not setting cookies. I have tried this…
Pankaj
  • 229
  • 5
  • 17
1
vote
3 answers

Detecting user language with Django

I'm looking for a way to detect user language. I set my default language as 'en_US', and I translated my site for 'pt_BR'. How can I switch the language and show 'pt_BR' version for Brazilians and 'en_US' for the rest of the world? I read these…
Alexandre Lara
  • 2,464
  • 1
  • 28
  • 35
0
votes
0 answers

Django translation.activate not working in middleware

I'm attempting to implement an auto language switcher in Django based on the client's IP address. For testing purposes, I've created a middleware to set the language to French ('fr'). class SetFrenchLanguageMiddleware: def __init__(self,…
0
votes
1 answer

How to change the default cookie name `django_language` set by `set_language()` in Django?

I could set and use set_language() as shown below: # "core/urls.py" ... urlpatterns += [ path("i18n/", include("django.conf.urls.i18n")) # Here ] Now, I want to change the default cookie name django_language below considering the security…
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
0
votes
1 answer

Why is Editing SessionStore Between Views in Django not Working

I have a session in django using django.sessions that I wish to alter using the SessionStore, but when I alter the Store and refresh the page (which is naturally updated by django's session middleware), the values are not persisted. For example,…
ViaTech
  • 2,143
  • 1
  • 16
  • 51
0
votes
0 answers

How to set a dictionary or list to a cookie and get it properly in Django?

I could set a dictionary or list to a session and get it properly as shown below: # "views.py" from django.http import HttpResponse def my_view(request): request.session['teacher'] = {'name': 'John', 'age': 36} …
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
0
votes
1 answer

Cookiecutter : Stop the execution of the cookiecutter if user gives no as input to one parameter

Cookiecutter.json has a parameter which accepts "yes" or "no": { "test" : [ "yes", "no"] } If a user selects "yes" then it should continue accepting the inputs further, if not it should stop. The same logic is included in pre_gen_project.py under…
0
votes
1 answer

Django doesn't set cookie and doesn't create session

I have a problem setting cookies in Django. Basically I have 3 different cookie I wanna set: Session ID Access token Refresh token For some reason Access and Refresh tokens are set, but the Session ID (SSID) doesn't set. If I change key of "SSID"…
1
2