Dariush
Dariush

Reputation: 483

How do I check which app a given view belongs to?

I'm writing a middleware with process_view method and I want it to apply only to the views in my app (not django.contrib.auth and other imported ones). How can this be done?

Upvotes: 1

Views: 167

Answers (1)

vorujack
vorujack

Reputation: 1950

you can use request url like this

def process_request(self, request):
    if request.path.startswith('any_prefix'):
        # do something
    else:
        # do other thing

also you can get view function file like this:

process_view(request, view_func, view_args, view_kwargs):
    if view_func.__module__ in ['module list']:
        # do something
    else:
        # do other thing

in this solution if your view wrapped checking module may not work.

Upvotes: 1

Related Questions