Checking user group membership in permission_required
<p>How would I check if a user is a part of a group inside the <code>permission_required</code> decorator?</p>

<p>This is what I have currently but it doesn't seem to check it..</p>

<pre><code>@permission_required(['user.is_super_user', "'NormalUser' in user.groups.all"], raise_exception=True)
</code></pre>

<p>This is supposed to check whether the user is a super user OR the user is part of the group <code>NormalUser</code> but when I try to access the site it just give me a 403 error when the user is part of the <code>NormalUser</code> group.</p>

<p>Is there a way I can get this done? I only want to use <code>permission_required</code> decorator, nothing else :S</p>

<p>I don't believe you can pass a perm check like the latter in your list, that's essentially trying to execute some python code, which won't work.</p>

<p>It would be handy to understand what your use case actually is, but if you strictly only want to use the permission_required decorator (instead of very simply creating your own decorator that does precisely what you want, or using the 'user_passes_test' decorator which seems more appropriate), then I would suggest you should <a href="https://docs.djangoproject.com/en/1.10/topics/auth/customizing/#custom-permissions" rel="nofollow">add a custom permission</a> somewhere in your system, add that as a permission of the 'Normal User' Group that you have created, and then just test (using permission required) the presence of that permission.</p>

<p>Depending on your use case will determine where you create this new permission.  Perhaps it's on a UserProfile type object ...</p>

python django python-2.7 django-admin django-views