On Tue, Jun 24, 2008 at 11:14 PM, csmith <[EMAIL PROTECTED]> wrote:
>
> How can I add an attribute or variable? to the request object in
> middleware, where I can use it in other views via the request object.
> This is my custom middleware code so far:
>
> class AliasMiddleware(object):
>    def process_request(self, request):
>        assert hasattr(request, 'session'), "The Django authentication
> middleware requires session middleware to be installed. Edit your
> MIDDLEWARE_CLASSES setting to insert
> 'django.contrib.sessions.middleware.SessionMiddleware'."
>        if request.POST:
>                request.fun = request.POST['username']
>        return None

One problem might be this line:

if request.POST:

As indicated in the docs(1) this is not the correct way to test if a
request is a POST request. You should instead do this:

if request.method == "POST":

Because of that, I suspect that your assignment of request.fun is
never actually happening.

Good luck,
/alex

(1) http://www.djangoproject.com/documentation/request_response/#attributes

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to