Courant News: Pages

Today’s topic of discussion is static pages in Courant News. Virtually all sites have static pages of some sort, such as an About page.  Following is a brief overview of how we have handled such a common feature.

Most static page requirements can be met with Django’s built-in Flatpages app. You define some template in which the content will get inserted, and then you can manage your static page contents through the admin interface. This is generally satisfactory for most purposes, but we ran into some use cases where additional functionality was required. If that’s all you need for your news site, there’s nothing wrong with sticking with Flatpages.

One shortcoming we ran into was the inability to put template functionality in our flatpage content. For example, at the YDN we have multiple “About” pages, covering our print staff, our online staff, and some other things. On each of those pages, we wanted to include our full masthead in a sidebar. Flatpages only lets you define one template for all your flatpages, so we couldn’t just include the masthead in this template because then it would be on other pages where we didn’t want it such as our Privacy Policy or our Legal pages.

Instead, we decided to bake our own simple pages application, which allows you to define a name, url, and a template with which to render the page. Because it is a normal Django template file, you can use whatever template logic you want, including the ability to {% extend %} and {% include %} other templates.  It also lets us generic dynamic URLs to other parts of the site, avoiding the terrible practice of hard-coding URLs in your website pages and templates. Because pages are objects just like any other type of content, they can be included in menus (which will be the topic of one of my next posts) and can be associated with other certain types of content.

Pages is a pretty simple feature, but one that stays out of your way and lets you do what you need to do without arbitrary limitations.

Leave a Reply