jazzband / django-waffle

A feature flipper for Django
https://waffle.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.12k stars 258 forks source link

Use a simpler (regex-free) URL definition #415

Closed DavidCain closed 2 years ago

DavidCain commented 2 years ago

This commit eliminates deprecation warnings that are raised on Django 3.1 or 3.2. Namely, urls.url() has been deprecated: URL definitions are encouraged to use one of either path or re_path.

When was url() deprecated?

The Django 3.1 "miscellaneous" release notes have a single bullet point about this change:

  • django.conf.urls.url() alias of django.urls.re_path() is deprecated

Are there alternatives?

The simplest change is to just use re_path instead of conf.urls.url, since Django 2.0 and greater have re_path available:

https://docs.djangoproject.com/en/2.0/ref/urls/#django.urls.re_path

However, there's no need to use regular expressions for a simple "match the start of the string, a pattern, then the end of the string."

Is this safe?

This change works on Django 2.0 or greater. django-waffle requires a minimum of Django 2.2 (earlier releases are not unsupported by Django anyway), so this should be a safe change.