配置: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+.文章来源:https://www.toymoban.com/news/detail-420210.html
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
.文章来源地址https://www.toymoban.com/news/detail-420210.html
到了这里,关于Python学习之路:Django项目遇到ImportError: cannot import name ‘url‘ from ‘django.conf.urls‘解决方法(亲测有效)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!