Last active
July 2, 2019 00:44
-
-
Save ricardodani/79fc797ccb66dde99aa331aaf489732e to your computer and use it in GitHub Desktop.
This file contains 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
from django.template.loader import get_template | |
from django.template.exceptions import TemplateDoesNotExist | |
class TemplateViewOrRedirect(TemplateView): | |
def get_template_names(self): | |
template_names = super().get_template_names() | |
for t in template_names: | |
get_template(t) | |
return template_names | |
def redirect_if_template_not_found(self): | |
raise NotImplementedError | |
def get(self, request, *args, **kwargs): | |
try: | |
return super().get(request, *args, **kwargs) | |
except TemplateDoesNotExist: | |
return self.redirect_if_template_not_found() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment