简体   繁体   中英

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. 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. When the function is completely removed, will the projects that use it have to change their source code?

will the projects that use it have to change their source code?

Yes , if they upgrade to , url will no longer be available.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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