diff --git a/README.md b/README.md index 76bb0a08..732b2d01 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,14 @@ Add a URL entry to your project’s urls.py, for example: ```python from django.conf import settings -from django.conf.urls import include, url +from django.conf.urls import include + +try: + from django.conf.urls import url +except ImportError: + # Django 4.0 replaced url by something else + # See https://stackoverflow.com/a/70319607/2519059 + from django.urls import re_path as url urlpatterns = [ # Your own url pattern here diff --git a/example_project/example_project/urls.py b/example_project/example_project/urls.py index a6f69427..505e9be6 100644 --- a/example_project/example_project/urls.py +++ b/example_project/example_project/urls.py @@ -13,7 +13,14 @@ 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ -from django.conf.urls import include, url +from django.conf.urls import include + +try: + from django.conf.urls import url +except ImportError: + # Django 4.0 replaced url by something else + # See https://stackoverflow.com/a/70319607/2519059 + from django.urls import re_path as url from django.contrib import admin urlpatterns = [url(r"^admin/", admin.site.urls), url(r"^survey/", include("survey.urls"))] diff --git a/setup.py b/setup.py index 58a976f3..b2581e18 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ LONG_DESCRIPTION = f.read() DEPENDENCIES = [ - "django>=2.2,<4", + "django>=2.2", "django-bootstrap-form>=3.4", "django-tastypie>=0.14.2", "django-registration>=3.0", diff --git a/survey/urls.py b/survey/urls.py index 938a334f..ca968758 100644 --- a/survey/urls.py +++ b/survey/urls.py @@ -1,4 +1,9 @@ -from django.conf.urls import url +try: + from django.conf.urls import url +except ImportError: + # Django 4.0 replaced url by something else + # See https://stackoverflow.com/a/70319607/2519059 + from django.urls import re_path as url from survey.views import ConfirmView, IndexView, SurveyCompleted, SurveyDetail from survey.views.survey_result import serve_result_csv diff --git a/urls.py b/urls.py index 001e2542..2b3b797d 100644 --- a/urls.py +++ b/urls.py @@ -1,6 +1,13 @@ # pylint: disable=invalid-name -from django.conf.urls import include, url +from django.conf.urls import include + +try: + from django.conf.urls import url +except ImportError: + # Django 4.0 replaced url by something else + # See https://stackoverflow.com/a/70319607/2519059 + from django.urls import re_path as url from django.contrib import admin from django.shortcuts import redirect from django.urls.base import reverse