Created
July 20, 2018 08:01
-
-
Save TBeijen/e54b2b7138348fe18539e5d68ff572d8 to your computer and use it in GitHub Desktop.
Django Redirect307View
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from django import http | |
from django.views.generic import RedirectView | |
logger = logging.getLogger('django.request') | |
class Redirect307View(RedirectView): | |
""" | |
Variant of RedirectView, to support 307 status instead of 302 | |
""" | |
url = None | |
pattern_name = None | |
query_string = False | |
def get(self, request, *args, **kwargs): | |
url = self.get_redirect_url(*args, **kwargs) | |
if url: | |
resp = http.HttpResponseRedirect(url, status=307) | |
return resp | |
else: | |
logger.warning( | |
'Gone: %s', request.path, | |
extra={'status_code': 410, 'request': request} | |
) | |
return http.HttpResponseGone() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment