[Fixed]-Restrict urls on certain apps in Django

1👍

You can get the current domain name (that the user is accessing) from request.META['HTTP_HOST']. Then based on that, raise 404 when the url is visited on certain domains.

from django.http import Http404
def my_restricted_view(request):
    domain = request.META['HTTP_HOST']
    if domain == 'sub.domain.com':
        return render(request, "template_name", {})
    else:
        raise Http404
👤masnun

Leave a comment