Search code examples
djangocontent-management

Django - Static content display based on URL


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?


Solution

  • 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...