Navigation in django

后端 未结 30 1502

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:39

    Thanks for your answers so far, gents. I've gone for something slightly different again..

    In my template:

    ...link...
  • ...link... ...link... ...link...

    Once I've worked out which page I'm on in the logic (usually in urls.py), I pass class="selected" as part of the context under the right name to the template.

    Eg if I'm on the link1 page, I'll append {'link1_active':' class="selected"'} to the context for the template to scoop up and inject.

    It appears to work and it's fairly clean.

    Edit: to keep HTML out of my controller/view, I've modified this a bit:

    ...link...
    ...link...
    ...
    

    It makes the template a little less readable, but I agree, it's better to not push through raw HTML from the urls file.

提交回复
热议问题