Skip to content

Instantly share code, notes, and snippets.

@doismellburning
Created December 20, 2016 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doismellburning/0b3f34c9b0a9e4abcceba5b307ae35eb to your computer and use it in GitHub Desktop.
Save doismellburning/0b3f34c9b0a9e4abcceba5b307ae35eb to your computer and use it in GitHub Desktop.
Running Django on EC2? Use this if you need your instance's IP in `ALLOWED_HOSTS`
try: # pragma: no cover
# From http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
_local_ip = requests.get(
'http://169.254.169.254/latest/meta-data/local-ipv4',
timeout=0.1,
).text
ALLOWED_HOSTS.append(_local_ip)
except requests.exceptions.RequestException:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment