Django运行项目时报错:
ImportError: cannot import name 'url' from 'django.conf.urls'
我的Django项目导入的模块如下:
from django.conf.urls import url
解决方法
这是因为django已经把django.conf.urls.url() 废弃掉了。
django.conf.urls.url() was deprecated in Django 3.0, and is removed in
Django 4.0+.
https://stackoverflow.com/questions/70319606/importerror-cannot-import-name-url-from-django-conf-urls-after-upgrading-to
最简单的方法是用
from django.urls import re_path as url
代替上面的
from django.conf.urls import url
文章出处登录后可见!
已经登录?立即刷新