Skip to content

Instantly share code, notes, and snippets.

@kaedroho
Last active August 29, 2015 13:57
Show Gist options
  • Save kaedroho/9485353 to your computer and use it in GitHub Desktop.
Save kaedroho/9485353 to your computer and use it in GitHub Desktop.
Routing change
def route_self(self, request, path_components):
"""
Override this if you want to use custom routing
"""
if path_components:
# path_components has been set but this page doesn't use custom routing
raise Http404
else:
return self.serve(request)
def route(self, request, path_components):
if self.live:
try:
return self.route_self(request, path_components)
except Http404:
pass
if path_components:
# request is for a child of this page
child_slug = path_components[0]
remaining_components = path_components[1:]
subpage = self.get_children().get(slug=child_slug)
return subpage.specific.route(request, remaining_components)
else:
raise Http404
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment