Skip to content Skip to sidebar Skip to footer

Django Is_ajax History Back

I wrote a Django view that responses ether a text/html or a application/json depending on request.is_ajax(). So far so good, but when I use my browsers history buttons, I end up ge

Solution 1:

If you send different content depending on request.is_ajax(), you need to send Vary: X-Requested-With to the browser. That way, the browser will be able to distinguish the two kinds of response based on the value of the X-Requested-With header on the request. You can do that via:

from django.views.decorators.vary import vary_on_headers

@vary_on_headers('X-Requested-With')
def yourview(request, ...):
    pass

Post a Comment for "Django Is_ajax History Back"