[Fixed]-How do I check in Django when on a subdomain or the main domain

1👍

in settings.py, you can use socket.gethostname()

import socket

if 'subdomain' in socket.gethostname():
    # set your subdomain
else:
    # set your maindomain

another version:

if socket.gethostname().split('.')[0] in ['subdomain1', 'subdomain2', ..]:
    # set socket.gethostname().split('.')[0] as subdomain

Leave a comment