• Home
  • Django
  • Force rerender the page after redirect 302 (not from browser cache)

Force rerender the page after redirect 302 (not from browser cache)

linkaiyi
Follow

browser will load the page from local cache if redirect with 302 to the page which is already saved in cache. e.g. set language function

solution is to add ? parameter to the url to force reload

    def get(self, request):
        language_code = request.GET.get("lang", settings.LANGUAGE_CODE)
        return_url = request.GET.get("next", "/home/")
        if return_url.find('?') != -1:
            return_url = return_url[:return_url.find('?')]
        translation.activate(language_code)
        request.session[translation.LANGUAGE_SESSION_KEY] = language_code
        request.session.modified = True
        # print(request.build_absolute_uri(return_url))
        return HttpResponseRedirect(request.build_absolute_uri(return_url) + '?setlanguage=' + str(time.time()))
Object has 0 attachments

Was this article helpful?

This article is viewed 21 times!

0 Comments

Leave a Comment

Support