266π
django.conf.urls.url()
was deprecated in Django 3.0, and is removed in Django 4.0+.
The easiest fix is to replace url()
with re_path()
. re_path
uses regexes like url
, so you only have to update the import and replace url
with re_path
.
from django.urls import include, re_path
from myapp.views import home
urlpatterns = [
re_path(r'^$', home, name='home'),
re_path(r'^myapp/', include('myapp.urls'),
]
Alternatively, you could switch to using path
. path()
does not use regexes, so youβll have to update your URL patterns if you switch to path.
from django.urls import include, path
from myapp.views import home
urlpatterns = [
path('', home, name='home'),
path('myapp/', include('myapp.urls'),
]
If you have a large project with many URL patterns to update, you may find the django-upgrade library useful to update your urls.py
files.
68π
I think a quick fix to this problem is to do followings;
You can easily replace
from django.conf.urls import url
to this:
from django.urls import re_path as url
And keep the rest of code to be same as before.
(Thanks @Alasdair)
- [Django]-Django 1.7 β App 'your_app_name' does not have migrations
- [Django]-Running a specific test case in Django when your app has a tests directory
- [Django]-When saving, how can you check if a field has changed?
2π
See in django version 4.0 it will not work.
So while installing Django in your Virtual Environment select this version
pip install django==3.2.10
This will definitely solve your error and in main urls.py do this:
from django.conf.urls import url
from django.urls import path,include
- [Django]-Django model blank=False does not work?
- [Django]-Django β {% csrf_token %} was used in a template, but the context did not provide the value
- [Django]-Laravel's dd() equivalent in django
-1π
I saw this thread, and thought this should just be a wrapper. So I asked a researcher friends GPT-4 bot Aria for this by Telegram, and my faithful servant made me a wrapper. Just put it at the top of your urls.py
and things start working again.
def url(regex, view, kwargs=None, name=None):
return re_path(regex, view, kwargs, name)
Solutions above seem plausible but complicated. If you want an easy fix, this is the one. It works and has restored my blog.
- [Django]-Why is logged_out.html not overriding in django registration?
- [Django]-How do you use the django-filter package with a list of parameters?
- [Django]-Automatic creation date for Django model form objects
-3π
If you are using django-rest-auth or any other package thats causing this error, what you should is to downgrade django.
pip install Django==3.2.19
- [Django]-Auto-create primary key used when not defining a primary key type warning in Django
- [Django]-IOS app with Django
- [Django]-What is the SQL ''LIKE" equivalent on Django ORM queries?