1

In Django, I have many sub domains and these have a theme installed to it. The problem is now I need to implement a function that redirects to the main domain of my project. For example when pressing a link ("Go to main domain") in the sub domain theme it will take them to the main domain.

I can hard code this, but it's not really nice. So I'm looking for other solutions to this.

This is a hardcoded way in views.py:

def network_url(request):
    return redirect('https://domain.com/')

So how do I create a function that do not require to hardcode the main domain?

1
  • You can get it from request object Commented Jan 5, 2016 at 11:55

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.