当前位置:   article > 正文

Python学习之路:Django项目遇到ImportError: cannot import name ‘url‘ from ‘django.conf.urls‘解决方法(亲测有效)_importerror: cannot import name 'url' from '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.

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号