简体   繁体   English

Django 中的 url() function 已被弃用 - 我必须更改我的源代码吗?

[英]The url() function in Django has been deprecated - Do I have to change my source code?

The url() function in django has been deprecated since version 3.1. django 中的 url() function自 3.1 版以来已被弃用。 Here's how backwards compatibility is being handled;以下是处理向后兼容性的方式;

def url(regex, view, kwargs=None, name=None):
    warnings.warn(
        'django.conf.urls.url() is deprecated in favor of '
        'django.urls.re_path().',
        RemovedInDjango40Warning,
        stacklevel=2,
    )
    return re_path(regex, view, kwargs, name)

For now, re_path() is returned when the url() function is called.目前,调用 url() function 时会返回 re_path()。 When the function is completely removed, will the projects that use it have to change their source code?当 function 完全移除后,使用它的项目是否必须更改其源代码?

will the projects that use it have to change their source code?使用它的项目是否必须更改其源代码?

Yes , if they upgrade to , url will no longer be available.的,如果他们升级到url将不再可用。

Typically if something is marked deprecated, it is removed two versions later, so in , since after , will be released.通常,如果某些东西被标记为弃用,它会在两个版本之后被删除,所以在中,因为在之后, 将被释放。 If you thus have an active project, you eventually will upgrade to Django-4.0 or further, and thus should make use ofre_path(…) [Django-doc] instead.如果您因此有一个活动项目,您最终将升级到 Django-4.0 或更高版本,因此应该使用re_path(…) [Django-doc]

The idea is thus to give users time to adapt the code accordingly, and keep the application running.因此,这个想法是让用户有时间相应地调整代码,并保持应用程序运行。 But one should eventually fix the deprecation warnings, since after ~16 months, it is removed in the newest Django versions.但是最终应该修复弃用警告,因为大约 16 个月后,它在最新的 Django 版本中被删除。

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

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