In another thread [1] James Bennett suggested to use a middleware to
require login for all views. That is indeed a very simple and elegant
way. Here's the code I ended up with:
from django.contrib.auth.decorators import login_required
from django.conf import settings
public_paths = ['/accounts/register/',
'/accounts/login/',
'/accounts/logout/',]
class AuthRequiredMiddleware(object):
def process_view(self, request, view_func, view_args,
view_kwargs):
if request.path.startswith(settings.MEDIA_URL) or request.path
in public_paths:
return None
else:
return login_required(view_func)(request, *view_args,
**view_kwargs)
Cheers!
Julien
[1]
http://groups.google.com/group/django-users/browse_thread/thread/2ab080ac86d9b820/b59196f5a0ecbd85#b59196f5a0ecbd85