Python学习之路:Django项目遇到ImportError: cannot import name ‘url‘ from ‘django.conf.urls‘解决方法(亲测有效)

配置:Pthon 3.8.10-Django 4.1.1

使用命令创建数据库时:

python manage.py migrate

提示错误:

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

经查阅相关资料,并实际操作,解决问题,具体办法往下:

修改生成项目下的urls.py文件中的:from django.conf.urls import url

为:from django.urls import re_path as url

重新运行,正常执行。

注:

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.

猜你喜欢

转载自blog.csdn.net/UniMagic/article/details/127078045