Hi

I still cant get this to work. Everything elese in the template works
fine, i.e. accessing several tables from the database.

I have the following in the settings.py

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

and the following in http.py in the middleware folder

class SetRemoteAddrFromForwardedFor(object):
    """
    Middleware that sets REMOTE_ADDR based on HTTP_X_FORWARDED_FOR, if
the
    latter is set. This is useful if you're sitting behind a reverse
proxy that
    causes each request's REMOTE_ADDR to be set to 127.0.0.1.

    Note that this does NOT validate HTTP_X_FORWARDED_FOR. If you're
not behind
    a reverse proxy that sets HTTP_X_FORWARDED_FOR automatically, do
not use
    this middleware. Anybody can spoof the value of
HTTP_X_FORWARDED_FOR, and
    because this sets REMOTE_ADDR based on HTTP_X_FORWARDED_FOR, that
means
    anybody can "fake" their IP address. Only use this when you can
absolutely
    trust the value of HTTP_X_FORWARDED_FOR.
    """
    def process_request(self, request):
        try:
            real_ip = request.META['HTTP_X_FORWARDED_FOR']
        except KeyError:
            return None
        else:
            # HTTP_X_FORWARDED_FOR can be a comma-separated list of
IPs. The
            # client's IP will be the first one.
            real_ip = real_ip.split(",")[0].strip()
            request.META['REMOTE_ADDR'] = real_ip

but still cant access the ip address.

Can anyone tell me what I am doing incorrectly.

Thanks

Ken

On Mar 15, 1:49 pm, "ge...@aquarianhouse.com"
<ge...@aquarianhouse.com> wrote:
> it seem to me, it's in the template.
>
> when it should work like this:
>
> {{ request.META.REMOTE_ADDR }}
>
> btw:
>
> > 'request.METTA['REMOTE_ADDR']' <--- in META is one T to much
>
> On Mar 15, 2:45 pm, Ken Lacey <ken.la...@dit.ie> wrote:
>
>
>
> > Hi
>
> > I am trying to access the remote addr in a view.
>
> > Using request.META['REMOTE_ADDR'] I get an error
>
> > Exception Type: TemplateSyntaxError
> > Exception Value: Could not parse the remainder: '['REMOTE_ADDR']' from
> > 'request.METTA['REMOTE_ADDR']'
>
> > How do I get over this?
>
> > Thanks
>
> > Ken- Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to