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

Viewed 3320

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?

1 Answers

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 of re_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.

Related