Middleware to resolve current URL to module and view

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
from django.core.urlresolvers import resolve


class GetCurrentViewMiddleware(object):

    def process_request(self, request):
        try:
            current_view = resolve(request.path)[0]
            # Handle wrappers
            if hasattr(current_view, 'view_func'):
                current_view = current_view.view_func
            # Saving back to request
            setattr(request, 'current_view', '%s.%s' % (current_view.__module__,
                                                        current_view.__name__))
        except:
            pass

More like this

  1. django subdomain support for both resolve and reverse. by puppy 2 years, 11 months ago
  2. Decorator to make files downloadable by prigun 4 years, 6 months ago
  3. Simple View Middleware to allow a Prefilter by tclineks 5 years, 1 month ago
  4. Serve static media and indexes from app directories [Python2.5, Development only] by adamlofts 4 years, 9 months ago
  5. CSRF this! by oggy 4 years, 8 months ago

Comments

(Forgotten your password?)