Use previously requested data in another request

18 views
Skip to first unread message

kayhan

unread,
Dec 3, 2021, 5:44:57 AM12/3/21
to Django users
Hi
I first send a request to Django and save its data with a session.
I will send another request to Django later. Here I want to use the data of the previous request.
But my code does not work properly. And the value "None" appears in the output.
Does anyone know what I should do?
Thankful

def planing(request): if request.is_ajax(): # Get user location from user location.js file: latitude = request.POST.get('latitude', None) longitude = request.POST.get('longitude', None) print("latitude, longitude = ", latitude,longitude) # To save data request.session['latitude'] = latitude request.session['longitude'] = longitude # To retrive data: latitude = request.session.get('latitude') longitude = request.session.get('longitude') print("latitude, longitude = ", latitude,longitude) elif request.method == "GET": return render(request, "tourist/planing.html") elif request.method == "POST": # To retrive data: latitude = request.session.get('latitude') longitude = request.session.get('longitude') print("latitude, longitude = ", latitude,longitude) Output: latitude, longitude = 34.801595 48.499574 latitude, longitude = 34.801595 48.499574 latitude, longitude = None None

Lalit Suthar

unread,
Dec 3, 2021, 12:25:32 PM12/3/21
to django...@googlegroups.com
We can save that in any django model in ajax() request if possible.

You can check if you have modified `SESSION_COOKIE_AGE` (https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SESSION_COOKIE_AGE)
if it is too less that might be the reason.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4bef9d07-cd92-440a-8ec0-dd4c206e6ae7n%40googlegroups.com.

kayhan

unread,
Dec 3, 2021, 12:50:21 PM12/3/21
to django...@googlegroups.com
Thanks but I did not change the settings.
And to test, SESSION_COOKIE_AGE = 5 * 60,
  I added to the settings but there is still the same problem.

Lalit Suthar

unread,
Dec 4, 2021, 3:03:27 AM12/4/21
to django...@googlegroups.com
tried to look into the docs but couldn't find a reason.
you can go through this page to find out any possible reason
https://docs.djangoproject.com/en/dev/topics/http/sessions/

kayhan

unread,
Dec 4, 2021, 4:31:45 AM12/4/21
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages