简体   繁体   中英

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

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

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM