views:

186

answers:

2

Since Django urls are arbitrary, including those set when you create flatpages. How can you figure out what a page's parent is? That is if I create a page /about/contact/, then when I am on the contact page (in the template), how can I figure out what the parent page is?

Is there a standard way to do this? Or do I just split the slug on the slashes and use the first section?

Basically I'm trying to figure out how to create different site sections.

+1  A: 

As far as I know, django doesn't have a native concept of sections and, as you said, the URLs are arbitrary (they're left to the programmer to decide). If you stick with the same URL structure throughout your whole site (/<section>/page) then you can infer the section from the URL.

I'd rather set the section in the url patterns and pass it to the views (as described in here) which in turn can pass it to the templates...

Miguel Ventura
A: 

flatpages are essentially the same thing as static html pages, stored in your database with a pretty admin in front of it.

so just hard code a link, it shouldn't be a big deal.

if it is a big deal, that means flatpages probably isn't the solution for you

phillc