1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 | ### last item in urlpatterns in urls.py
(r'^(?P<full_slug>(.*))/$', 'myproject.myapp.views.pages')
### myview
from django.http import Http404
from django.shortcuts import get_object_or_404
def pages(request, full_slug):
slugs = full_slug.split('/')
page_slug = slugs[-1]
page = get_object_or_404(Page,slug=page_slug)
if not page.get_absolute_url().strip('/') == full_slug:
raise Http404
### if you reach this line, you've found the page
### in page model
def get_absolute_url(self):
url = "/%s/" % self.slug
page = self
while page.parent:
url = "/%s%s" % (page.parent.slug,url)
page = page.parent
return url
|
Comments
Would it be possible to show all the children of a parent? For example:
/about/ -- /about/tom/ -- /about/richard/ -- /about/jane/ ---- /about/jane/hobbies/ ---- /about/jane/education/
What would be the best to approach this extraction?
#
Someone in the IRC #django mentioned this:
obj.page_set.all()
#
How would you pull the data out from the view to the template?
#