1from django.utils.http import is_safe_url 2 3 4def get_valid_next_url_from_request(request): 5 next_url = request.POST.get('next') or request.GET.get('next') 6 if not next_url or not is_safe_url(url=next_url, allowed_hosts={request.get_host()}): 7 return '' 8 return next_url 9