O
O
Oleg2015-03-27 23:16:42
Django
Oleg, 2015-03-27 23:16:42

Django how to configure authorization by prefixes?

I've been picking Django for a week - I ask you not to throw tomatoes.
In general, I have three classes extending the User model - Admin, Kid and Teacher
urls.py

urlpatterns = patterns(
    ...
    url(r'^kid/', include('users.urls_kid')),
    url(r'^teacher/', include('users.urls_teacher')),
    url(r'^admin/', include('users.urls_admin')),
    ...

Actually, now I want to hang a check on the corresponding urls - whether the user class matches the prefix of the site section. I found the user_passes_test decorator - but I can't get the whole thing to work.
Question: is it possible to use user_passes_test and include inside url()? And if so, how?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2015-03-28
@FireGM

user_passes_test is better used as a decorator on a view. Accepts a reference to a function that should return a boolean value (true, false). Inside the function, you can do any kind of checks. Better yet, use CBV and mixins.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question