Closed ec4you2022 closed 8 months ago
You are probably using a too old version of the package.
Had the same issue while using django 4.2.14 To avoid open redirects for security reseasons, I installed is_safe_url as a stand alone package pip install is_safe_url Then, from is_safe_url import is_safe_url
if is_safe_url(next_url, allowed_hosts={request.get_host()}): return redirect(next_url) else: return redirect('home')
Django has renamed is_safe_url
to url_has_allowed_host_and_scheme
in Django 3.0 and is_safe_url
has been removed in Django 4.0. Django-two-factor-auth supports Django 4.2 and later and thus imports url_has_allowed_host_and_scheme
and not is_safe_url
. If you get an import error for is_safe_url
, this is likely a problem in your own code or another package and this can be fixed by changing is_safe_url
to url_has_allowed_host_and_scheme
.
Thanks
On Sun, 20 Oct 2024, 16:49 Jeroen Dekkers, @.***> wrote:
Django has renamed is_safe_url to url_has_allowed_host_and_scheme in Django 3.0 and is_safe_url has been removed in Django 4.0. Django-two-factor-auth supports Django 4.2 and later and thus imports url_has_allowed_host_and_scheme and not is_safe_url. If you get an import error for is_safe_url, this is likely a problem in your own code or another package and this can be fixed by changing is_safe_url to url_has_allowed_host_and_scheme.
— Reply to this email directly, view it on GitHub https://github.com/jazzband/django-two-factor-auth/issues/714#issuecomment-2424971901, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATXJ273OO4LOUQFXTGR6EI3Z4OYF3AVCNFSM6AAAAABQHOQTLWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRUHE3TCOJQGE . You are receiving this because you commented.Message ID: @.***>
File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\currencies\urls.py", line 4, in
from currencies.views import set_currency
File "C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\currencies\views.py", line 4, in
from django.utils.http import is_safe_url
ImportError: cannot import name 'is_safe_url' from 'django.utils.http' (C:\Users\Admin\AppData\Local\Programs\Python\Python311\Lib\site-packages\django\utils\http.py)