Skip to content

Instantly share code, notes, and snippets.

@dolugen
Created September 21, 2011 12:53
Show Gist options
  • Save dolugen/1231953 to your computer and use it in GitHub Desktop.
Save dolugen/1231953 to your computer and use it in GitHub Desktop.
# from http://docs.webfaction.com/software/django/troubleshooting.htmlhighlight=django%20remote%20addres#accessing-remote-addr
class WebFactionFixes(object):
"""Sets 'REMOTE_ADDR' based on 'HTTP_X_FORWARDED_FOR', if the latter is
set.
Based on http://djangosnippets.org/snippets/1706/
"""
def process_request(self, request):
if 'HTTP_X_FORWARDED_FOR' in request.META:
ip = request.META['HTTP_X_FORWARDED_FOR'].split(",")[0].strip()
request.META['REMOTE_ADDR'] = ip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment