Skip to content

Instantly share code, notes, and snippets.

@bdunnette
Created January 28, 2020 16:53
Show Gist options
  • Select an option

  • Save bdunnette/d46310324cc7f001763a33f294f3cd58 to your computer and use it in GitHub Desktop.

Select an option

Save bdunnette/d46310324cc7f001763a33f294f3cd58 to your computer and use it in GitHub Desktop.
# Get local hostname & IP, add these to Django's ALLOWED_HOSTS
import socket
import netifaces as ni
DEFAULT_INTERFACE = os.getenv('DEFAULT_INTERFACE', default='enp3s4f0')
DEFAULT_IP = ni.ifaddresses(DEFAULT_INTERFACE)[ni.AF_INET][0]['addr']
DEFAULT_HOSTNAME = socket.gethostname()
ALLOWED_HOSTS = ['localhost', '127.0.0.1', DEFAULT_IP, DEFAULT_HOSTNAME]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment