Login

Snippets by brianjaystanley

Snippet List

Get Client IP Behind Proxy

If your application server is behind a proxy, `request.META["REMOTE_ADDR"]` will likely return the proxy server's IP, not the client's IP. The proxy server will usually provide the client's IP in the `HTTP_X_FORWARDED_FOR` header. This util function checks both headers. I use it behind Amazon's Elastic Load Balancer (ELB).

  • request
  • ip
Read More

Persistent Session Debugging with Django Debug Toolbar

When using [django debug toolbar](https://github.com/django-debug-toolbar/django-debug-toolbar), I like to be able to turn debugging on and off without having to edit my settings file. This callback makes that possible. Add `?debug=on` to the URL to turn debugging on. It will remain on in the current session until you turn it off with `?debug=off`. Make sure your session middleware comes before your debug toolbar middleware.

  • session
  • debug
  • debug-toolbar
Read More

brianjaystanley has posted 2 snippets.