[Answer]-How to get current domain in django views without `com` or `eu`?

1👍

You would have to do some manual labor to get just the domain name.

Using request.META['HTTP_HOST'] will give you the domain, but it’s generally a bad idea since it can be spoofed (ie. faked).

But let’s play anyways! I will be using the Python slice syntax.

def domain(domain):
    return domain[:domain.rfind('.')]

>> domain(request.META['HTTP_HOST']) #http://www.website.whatever
>> "http://www.website"

Leave a comment