The example provides a snippet for an application level view, but what if I have lots of different (and some non-application) entries in my “urls.py” file, including templates? How can I apply this login_required decorator to each of them?
(r'^foo/(?P<slug>[-\w]+)/$', 'bugs.views.bug_detail'),
(r'^$', 'django.views.generic.simple.direct_to_template', {'template':'homepage.html'}),
Dropped this into a
middleware.pyfile in my project root (taken from http://onecreativeblog.com/post/59051248/django-login-required-middleware)Then appended
projectname.middleware.LoginRequiredMiddlewareto my MIDDLEWARE_CLASSES in settings.py.