Skip to content

Commit

Permalink
auto redirect invalid hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
mein Name authored and alphatownsman committed Feb 9, 2025
1 parent a527108 commit 2d7ff41
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions common/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.core.cache import cache
from django.core.exceptions import DisallowedHost
from django.http import HttpRequest, JsonResponse
from django.shortcuts import redirect, render
from django.urls import reverse
Expand Down Expand Up @@ -81,6 +82,9 @@ def nodeinfo2(request):


def error_400(request, exception=None):
if isinstance(exception, DisallowedHost):
url = settings.SITE_INFO["site_url"] + request.get_full_path()
return redirect(url, permanent=True)
return render(request, "400.html", status=400, context={"exception": exception})


Expand Down

0 comments on commit 2d7ff41

Please sign in to comment.