Question

Currently in my django app, I have two kind of users, say userTypeA and userTypeB.

At this point, I redirect both of the types to /usercheck/ which has a function to check the type of user, and redirect them accordingly. This is working out pretty well.

However, just for curiosity, if I were to write a decorator where would I put it ?

One place I can think of is settings.py where a decorator will output different LOGIN_REDIRECT_URL based on the user type.

It is just for learning. My current implementation is working out pretty good so far.

Thanks a lot.

Was it helpful?

Solution

settings.py is meant for global static configuration data, I would definitely not try dynamically changing the settings. There are many other places in Django where a login url can be set explicitly.

I'm not entirely clear on what you want to do, but it sounds like the user_passes_test decorator is what you're after. From the docs:

Limiting access to logged-in users that pass a test: The simple way is to run your test on request.user in the view directly.... As a shortcut, you can use the convenient user_passes_test decorator.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top