Reputation: 648
Is there something between middleware
and view so that I can plug my code or do I have to subclass something from Django
to provide this functionality?
Let me first explain why I need this, maybe there is a better solution that you can suggest. I want to restrict some of my url's based on some configuration. And, - I want this configuration to be part of url configuration - According to the config provided, I want to redirect, etc to some other view.
What I mean by 'part of url configuration' is something like the following.
url(r'^admin/blah/blah$', do_something, name='admin-blah-blah', {'security_level': 'very_secure', 'auth_method' : 'oauth', 'auth_url', 'http://www.foo.com'})
It seems like it is something that should be done by middlewares, but I don't want to do it with middlewares for 2 reasons. - I don't want to maintain a separate config. - I don't want to do regex matching for url patterns one more time, url resolver is already doing that
So if I can just find a way to plug some functionality just before view and can reach the configuration provided, it solves my problem.
Upvotes: 1
Views: 168
Reputation: 600059
Sounds like you could do this with a decorator on your views:
@restrict_url(security_level='very_secure', auth_method='oauth',
auth_url= 'http://www.foo.com')
def my_view(request):
... etc ...
You can get some ideas of how to write the restrict_url
decorator by looking at the ones provided in django.contrib.auth.decorators
.
Upvotes: 4