[Answered ]-Get main domain url without hardcoding

2👍

Just store your links in settings.py.

MAIN_DOMAIN_LINK = 'https://domain.com/'

Then, you can simply access them by importing django.conf.settings in your views:

from django.conf import settings

def network_url(request):
    return redirect(settings.MAIN_DOMAIN_LINK)

Hope this helps. Docs link.

0👍

Try this

def network_url(request):
    return redirect(request.META.get("HTTP_HOST"))

Leave a comment