views:

68

answers:

3

I'm working on a Django site with a basic three column design. Left column navigation, center column content and right column URL specific content blocks.

My question is about the best method of controlling the URL specific content blocks in the right column.

I am thinking of something along the lines of the Flatpages app that will make the content available to the template context if the URL matches a pre-determined pattern (perhaps regex?).

Does anyone know if such an app already exists?

If not, I am looking for some advice about the best way to implement it. Particularly in relation to the matching of patterns to the current URL. Is there any good way to re-use parts of the Django URL dispatcher for this use?

+1  A: 

For something like this I personally would use Django CMS. It's like flatpages on steroids.

Django CMS has a concept of Pages, Templates, and Plugins. Each page has an associated template. Templates have placeholders where you can insert different plugins. Plugins are like mini-applications that can have dynamic model-based content.

digitaldreamer
That looks like an interesting solution. I think it would work great with static pages of the site. My only concern is how it works with the rest of the site, all of the custom Django views.
Steven Potter
It plays nicely with other applications. You can either integrate applications straight into the Paging framework, or just include them into the django project like you would if you weren't using Django CMS. It's pretty flexible and doesn't take much effort to integrate. I'd recommend taking the time to at least read through the documentation. It's not very long. Django CMS might not be useful for your current problem, but it might be a lifesaver for another project in the future. It was for me.
digitaldreamer
+1  A: 

Django CMS is a good suggestion, it depends on how deep you want to go. If this is just the beginning of different sorts of dynamic content you want then you should go that way for sure.

A simple one-off solution would be something like this:

You would just need to write a view and add some variables on the end of the URL that would define what showed up there. Depending on how fancy you need to get, you could just create a simple models, and just map the view to the model key

www.example.com/content/sidecontent/jokes/

so if "jokes" was your block of variable sidecontent (one of many in your sides model instances) the urls.py entry for that would be

(r'^content/sidecontent/(?P<side>)/$,sides.views.showsides),

and then in your sides app you have a view with a

def showsides(request, side):
    Sides.objects.get(pk=side)

etc...

zenWeasel
A: 

Although Django-CMS is an interesting suggestion, there are quite a few projects that do specifically what you've requested - render blocks of content based on a URL. The main one that I know about is django-flatblocks.

Daniel Roseman
This is more in the direction I was originally thinking. However as far as I can tell, it would still require that I place a specific template tag for each "flatblock". What I have in mind is more of a class of flatblocks, and the appropriate one is displayed based on URL pattern matching. If I can't find what I am looking for this seems like it would be a good place to start to roll my own.
Steven Potter