Django - how to use user_pass_test with URLs

advertisements

I'm trying to use user_pass_test in my URL's definitions for CBV and views.

I want to use a similar syntax to this:

url (r'^question_detail-(?P<pk>\w+)$', user_passes_test(not_in_group_chef,
login_url='public_connexion')Question_detail.as_view(), name='detail_question')

I found : Django - limiting url access to superusers and http://jonatkinson.co.uk/djangos-user_passes_test-and-generic-views/

But it's not functional in my case.

Thank you.


you are missing a pair of brackets in your code example, does this work?

url (
    r'^question_detail-(?P<pk>\w+)$',
    user_passes_test(not_in_group_chef, login_url='public_connexion')(
        Question_detail.as_view()
    ),
    name='detail_question'
)