简体   繁体   English

DRF - 从 django.conf.urls 在 Django 4.0 中导入 url

[英]DRF - from django.conf.urls import url in Django 4.0

I've a project in django 3.2 and I've updated (pip install -r requirements.txt) to version 4.0 (new release) and I've currently the below error when I run the server in a virtual environment.我在 django 3.2 中有一个项目,并且我已将(pip install -r requirements.txt)更新到版本 4.0(新版本),当我在虚拟环境中运行服务器时,我目前出现以下错误。 I use DRF.我使用 DRF。

Can't import => from rest_framework import routers in urls.py无法从 urls.py 中的 rest_framework 导入路由器导入 =>

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

As per the Django docs here :根据此处的 Django 文档:

url(regex, view, kwargs=None, name=None)¶ This function is an alias to django.urls.re_path(). url(regex, view, kwargs=None, name=None)¶ 这个 function 是 django.urls.re_path() 的别名。

Deprecated since version 3.1: Alias of django.urls.re_path() for backwards compatibility. 3.1 版后已弃用:django.urls.re_path() 的别名以实现向后兼容性。

django.conf.urls.url() was deprecated since Django 3.1, and as per the release notes here , is removed in Django 4.0+. django.conf.urls.url()自 Django 3.1 起已弃用,根据此处的发行说明,已在 Django 4.0+ 中删除。

You can resolve the issue using path or re_path .您可以使用pathre_path解决问题。

https://docs.djangoproject.com/en/4.0/ref/urls/ https://docs.djangoproject.com/en/4.0/ref/urls/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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