开发者

django: dynamically populate nav elements

开发者 https://www.devze.com 2023-01-19 03:56 出处:网络
I am writing a blog application as a part of a larger website. I want to have a main (static) nav bar for the site navigation, but I want to have a sub nav that allows the user to filter the blog post

I am writing a blog application as a part of a larger website. I want to have a main (static) nav bar for the site navigation, but I want to have a sub nav that allows the user to filter the blog posts by other criteria when viewing the blog.

Something like

Latest | Popular | Category | Author | Date | Tag
                 |-> News   | Dave   | Year | X
                 |-> Django | Peter  | Month| Y 
                 |-> etc.   | etc.   | etc. | etc.

where the 2nd level of the nav is automatically generated from the categorie, tag, user etc.

I know I could pass the model objects as a part of the context in the views/generic views, but this seems to be a bad option, as I'd be 开发者_开发百科repeating myself for every view in the blog application. Surely there is some easier way of doing this?


You could have a look at zinnia blog which provides the functionality you need. It also integrates very well with django-cms and provides together with the cms' menus app EXACTLY the menu structure you desire! If you do not want to use it, have a look at its template tags to see how the navigation you desire is generated!

0

精彩评论

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