      if not is_safe_url(url=next, host=request.get_host()):
          next = request.META.get('HTTP_REFERER')
          if not is_safe_url(url=next, host=request.get_host()):
              next = '/'
      response = http.HttpResponseRedirect(next)
      if request.method == 'POST':
          lang_code = request.POST.get(LANGUAGE_QUERY_PARAMETER)
          if lang_code and check_for_language(lang_code):
              next_trans = translate_url(next, lang_code)
              if next_trans != next:
 
</s> remove     if not is_safe_url(url=next, host=request.get_host()):
 </s> add     if (next or not request.is_ajax()) and not is_safe_url(url=next, host=request.get_host()): </s> remove             next_trans = translate_url(next, lang_code)
            if next_trans != next:
                response = http.HttpResponseRedirect(next_trans)
 </s> add             if next:
                next_trans = translate_url(next, lang_code)
                if next_trans != next:
                    response = http.HttpResponseRedirect(next_trans) </s> remove         lang_code, lang_name = settings.LANGUAGES[0]
 </s> add         lang_code = self._get_inactive_language_code() </s> remove         for lang_code, lang_name in settings.LANGUAGES:
            post_data = dict(language=lang_code, next='/')
            response = self.client.post('/i18n/setlang/', data=post_data)
            self.assertRedirects(response, '/')
            self.assertEqual(self.client.session[LANGUAGE_SESSION_KEY], lang_code)
 </s> add         lang_code = self._get_inactive_language_code()
        post_data = dict(language=lang_code, next='/')
        response = self.client.post('/i18n/setlang/', post_data, HTTP_REFERER='/i_should_not_be_used/')
        self.assertRedirects(response, '/')
        self.assertEqual(self.client.session[LANGUAGE_SESSION_KEY], lang_code)
    response = http.HttpResponseRedirect(next) if next else http.HttpResponse(status=204)
      if not is_safe_url(url=next, host=request.get_host()):
          next = request.META.get('HTTP_REFERER')
          if not is_safe_url(url=next, host=request.get_host()):
              next = '/'
    response = http.HttpResponseRedirect(next) if next else http.HttpResponse(status=204)
      if request.method == 'POST':
          lang_code = request.POST.get(LANGUAGE_QUERY_PARAMETER)
          if lang_code and check_for_language(lang_code):
              next_trans = translate_url(next, lang_code)
              if next_trans != next:
keep keep keep keep replace keep keep keep keep keep
 Fixed #21446 -- Allowed not performing redirect in set_language view

Thanks Claude Paroz and Tim Graham for polishing the patch. 
django/views/i18n.py