20.5 Conditionally Displaying Template Links

While our webpages are now fully protected, many of our templates still link to these protected views. We will be displaying links to views that unauthenticated users cannot reach, which is misleading.

Thankfully, as shown in Example 20.61, we can check permissions in the template thanks to the perms variable, added in by context processor (therefore requiring RequestContext).

Example 20.61: Python Code

{% if perms.organizer.add_tag %} {% if perms.organizer.change_tag %} {% if perms.organizer.delete_tag %}

Much as we did with the CSS conditional checks we created in Chapter 16: Serving Static Content with Django, we can use basic logic to change how our webpages are ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.