Thursday 12 November 2020

How can I catch django.http.request.DisallowedHost in a view?

This works:

def index(request):

    try:
        # Do some stuff

    except:
        return render(request, 'something.html')

But how can I catch just the error: django.http.request.DisallowedHost ?

Have tried this and it doesn't work:

from django.core.exceptions import DisallowedHost

def index(request):

    try:
        # Do some stuff

    except DisallowedHost:
        return render(request, 'something.html')



from How can I catch django.http.request.DisallowedHost in a view?

No comments:

Post a Comment