28👍
re_path
is an implementation of the ‘old’ way of handling urls, which was previously (version <2) done by url
from django.conf.urls
.
See the paragraph in Django 2.0 release notes about this.
This being said, I recommend using path
whenever you can!
The reasons I see:
-
path
was introduced with the goal of making things simpler, which is clearly the direction the Django devs want to go. So, when usingpath
you are following this direction, thus minimizing the risk of having to adapt your codebase to new changes. -
While
path
is not just a result of an attempt of making things simpler, it actually really does make things simpler and more readable, which is a good reason alone to whypath
should be preferred if both choices are an option.
Now re_path
exists for reasons, so there are cases when using re_path
might still be a better option. One scenario is clearly when require very customized converter and reach the limit of what is feasible with custom converters for ‘path’. Yet another scenario to use re_path
could be when upgrading a system with rather complex url-converters form a Django 1.x to a 2.x: Simply replacing the url
with re_path
commands can be much more time-efficient and thus be a desirable approach.
2👍
You got it. The newer path
syntax makes for much cleaner URL patterns. You can write your own path converters, too, so that more of your paths can use path
instead of re_path
.
- Why does python new york time zone display 4:56 instead 4:00?
- Django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL refers to model 'auth.User' that has not been installed
- Installing Django with pip