Reputation: 4404
Is it necessary in Django to name urls for use in the url template tag?
The following url example is given in the documentation:
('^client/([0-9]+)/$', 'app_views.client', name='app-views-client')
and can be used in a template like this:
{% url 'app-views-client' client.id %}
But is there some way to reverse views by path instead of name? There is a way that is deprecated in 1.8 and will be removed in Django 2.0, like this:
{% url 'path.to.some_view' v1 %}
In 1.8 and beyond is there still a way to reverse a view without naming it?
Upvotes: 2
Views: 1794
Reputation: 127200
If you want to be forward compatible, named urls will become necessary.
The deprecation timeline for version 2 states:
The ability to reverse() URLs using a dotted Python path will be removed.
Internally, the url tag uses reverse, so it will be subject to the same deprecation. This is mentioned at the end of the docs for the url tag.
If you want to reverse by path still, you could look at the source for how it's done now and replicate that manually. But there's probably a good reason behind the decision to remove this ability.
Upvotes: 5