Created
December 20, 2016 13:51
-
-
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`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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