ImportError: cannot import name 're_path' from 'django.conf.urls'

Viewed 279

I'm following a Django tutorial and trying to update a urls.py file with the following code:

from django.contrib import admin
from django.urls import path

from django.conf.urls import re_path, include


urlpatterns=[
    path('admin/', admin.site.urls),
    re_path(r'^',include('EmployeeApp.urls'))
]

When I run the server with python manage.py runserver I get the following error:

ImportError: cannot import name 're_path' from 'django.conf.urls' (C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\django\conf\urls\__init__.py)

I'm running version 4.0.4 of Django:

py -m django --version # Prints: 4.0.4
1 Answers

I needed to change

from django.conf.urls import re_path, include

to:

from django.conf.urls import include
from django.urls import re_path

Now the error has stopped. (Documentation)

Related