开发者

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. Particula开发者_开发百科rly 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?


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜