Navigation in django

后端 未结 30 1503

I\'ve just done my first little webapp in django and I love it. I\'m about to start on converting an old production PHP site into django and as part its template, there is a

30条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 09:59

    I have multiple menus on the same page that are created dynamically through a loop. The posts above relating to the context gave me a quick fix. Hope this helps somebody. (I use this in addition to the active template tag - my fix solves the dynamic issue). It seems like a silly comparison, but it works. I chose to name the variables active_something-unique and something-unique, this way it works with nested menus.

    Here is a portion of the view (enough to understand what i am doing):

    def project_list(request, catslug):
        "render the category detail page"
        category = get_object_or_404(Category, slug=catslug, site__id__exact=settings.SITE_ID)
        context = {
            'active_category': 
                category,
            'category': 
                category,
            'category_list': 
                Category.objects.filter(site__id__exact=settings.SITE_ID),
    
        }
    

    And this is from the template:

    
    

提交回复
热议问题