0

ImportError: cannot import name 'url' from 'django.conf.urls' (/home/chams/pfe_project/CarApp/venv/lib/python3.8/site-packages/django/conf/urls/_init_.py)

I can't find any mistakes in my code !

zayet chams
  • 1
  • 1
  • 1
  • Does this answer your question? [ImportError: cannot import name 'url' from 'django.conf.urls' after upgrading to Django 4.0](https://stackoverflow.com/questions/70319606/importerror-cannot-import-name-url-from-django-conf-urls-after-upgrading-to) – Maxypoo Jun 06 '22 at 15:21

3 Answers3

1

django.conf.urls.url was deprecated and removed in Django 4.0.

Use django.urls.re_path instead.

dgw
  • 13,418
  • 11
  • 56
  • 54
1

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()

You will be using this,

from django.conf.urls import url

Instead use this:

from django.urls import re_path as url

  • 1
    While this is an answer, it's a "copy" of the previous answers https://stackoverflow.com/a/71628531/6143954. There is no additional value for SO to keep multiple answers with the same solution. – NKSM Apr 29 '22 at 18:17
  • I have the same error I can't understand what you say. this error happened in the library not in my code the path error occurs is: venv/lib/python3.10/site-packages/compat/__init__.py – minttux Aug 11 '23 at 05:24
1

for Django 4.0.

from django.urls import re_path as url