Skip to content

Instantly share code, notes, and snippets.

@ricardodani
Last active July 2, 2019 00:44
Show Gist options
  • Save ricardodani/79fc797ccb66dde99aa331aaf489732e to your computer and use it in GitHub Desktop.
Save ricardodani/79fc797ccb66dde99aa331aaf489732e to your computer and use it in GitHub Desktop.
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