Home > OS >  django - restrict visibility of divs for specific user group
django - restrict visibility of divs for specific user group

Time:10-21

I have created a blog app in Django framework. I have set up a login, logout, and sign up authentication system so authorized users can see everything and unauthorized can see only the home page. I am using django cms so people can add and edit content on website. I created 2 groups of users on admin page: managers and editors. Managers do everything and editors have limited permissions.

I'd like to apply something like this but directly on blog post pages and limit elements in my Blog posts (DetailvedView pages) for editors.

I have 2 divs in my blog post page. First div(class='everyone') should be visible for everyone and the second div (class='managers') should be visible only for managers group?

I want to give permissions not only by using user.is_authenticated but extend it and decide what each group of users see on website.

CodePudding user response:

If you are looking to check for permissions in templates, this is how you can do :

In general :

{% if perms.app_label.can_do_something %}
<!-- Some div here -->
{% endif %}

In your case : We suppose that is_manager is the permission to check id a user is manager or not

{% if perms.app_label.is_manager %}
<!-- Show what managers only can see here -->
{% endif %}
<!-- Here everyone can see -->

More info here, and this post

  • Related