Skip to content

Commit 13e522c

Browse files
committed
Prevented is_safe_url() deprecation warning.
1 parent 6d4a190 commit 13e522c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

django_comments/compat.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
"""
22
Module to store compatiblity imports to prevent Django deprecation warnings.
33
"""
4+
try:
5+
# Introduced in Django 3.0.
6+
from django.utils.http import url_has_allowed_host_and_scheme
7+
except ImportError:
8+
from django.utils.http import is_safe_url as url_has_allowed_host_and_scheme

django_comments/views/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from django.http import HttpResponseRedirect
99
from django.shortcuts import render, resolve_url
1010
from django.core.exceptions import ObjectDoesNotExist
11-
from django.utils.http import is_safe_url
11+
12+
from ..compat import url_has_allowed_host_and_scheme
1213

1314
import django_comments
1415

@@ -24,7 +25,7 @@ def next_redirect(request, fallback, **get_kwargs):
2425
Returns an ``HttpResponseRedirect``.
2526
"""
2627
next = request.POST.get('next')
27-
if not is_safe_url(url=next, allowed_hosts={request.get_host()}):
28+
if not url_has_allowed_host_and_scheme(url=next, allowed_hosts={request.get_host()}):
2829
next = resolve_url(fallback)
2930

3031
if get_kwargs:

0 commit comments

Comments
 (0)