Make clicked tab active in Bootstrap

后端 未结 10 640
傲寒
傲寒 2021-01-31 09:02

I am using Django and integrated Bootstrap with Django. Here is my HTML code for the navigation bar:

10条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-31 09:36

    @rphonika has give a nice answer. But if you have many navigation menus then adding template logic in each list item makes the code untidy. Menu items can be assigned a unique id, the id passed in views and active class can be assigned using a one liner javascript code in html itself.

    base.html

    
    .
    .
    .
    
    

    views.py

    def overview(request):
        ...
        return render(request, 'overview.html', {'nmenu': 'overview'})
    
    
    def plot(request):
        ...
        return render(request, 'plot.html', {'nmenu': 'plot'})
    

    And so on for other views

提交回复
热议问题