Friday, September 30, 2011

Re: set_test_cookie() on every page?


John - thanks for the reply.

In this case, it's an JQuery .post() call linked to a dropdown menu (

The dropdown is a common navigation element on every page. It's used to set a session variable that stores which object a user is working on at the 
moment (see attached screenshot).

In my webpage:

  $('#dropdown_choice').click(function() {
        $.post("/set_conference", {"current_conference": "conference_name"}, function(data) {alert(data)});

Then in my view:

# TODO: Set test cookies (although if we're logged in, we can assume cookies works)
def set_current_conference(request):
    if not request.is_ajax() or not request.method == 'POST':
        return HttpResponseNotAllowed(['POST'])
    request.session['current_conference'] = request.POST.get("current_conference")
    return HttpResponse('Set current_conference to ' + str(request.POST.get("current_conference")))
So it seems I would need to put the set_test_cookie() logic on every page, since they could make this call from any page with the dropdown. Or is there another way?

How would people normally handle having an AJAX POST call like this to set a session variable?

Or should I just (dangerously) assume that cookies will work automatically? Alternative?


You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment