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


The line in question is:

 request.fun = request.POST['username']

Do I need to add it to request.session? I was pretty sure that I could
add to the request object but it doesn't seem to work when I try
accessing the variable(should I call it an attribute? I have a C
background and still don't understand python that good yet) in my
views. I have the session and authentication middleware enabled like
so:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'mysite.middleware.AliasMiddleware',
    'django.middleware.doc.XViewMiddleware',
)

Thanks for any help you can give me!

csmith
--~--~---------~--~----~------------~-------~--~----~
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