On 5/15/07, Christian M Hoeppner <[EMAIL PROTECTED]> wrote:
>
> Hi there!
>
> How would one handle the following tasks in a middleware?
Put this somewhere in your app:
======
class MaintenanceMiddleware(object):
def process_request(self, request):
from django.conf import settings
from django.http import HttpResponseRedirect
if settings.MAINTENANCE and not request.user.is_authenticated()
return HttpResponseRedirect("/maintenance/")
return None
=======
Then add that to your MIDDLEWARE_CLASSES list; make sure it's after
AuthenticationMiddleware so that request.user exists.
Request middleware short-circuits the request cycle if it returns a
HttpResponse instance.
More:
http://www.djangoproject.com/documentation/middleware/#process-request
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---