#22384 closed Cleanup/optimization (fixed)
Deprecate the ability to reverse by dotted path
Reported by: | Tim Graham | Owned by: | Tim Graham |
---|---|---|---|
Component: | Core (URLs) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Now that we've deprecated patterns()
and recommended actually importing your views module and referencing your view functions (or classes) directly (#22218), I think it's time to deprecate the "Django String Magic" (as Carl termed it) that lets you use strings in url()
, e.g. url('^$', 'myapp.views.myview')
. As well as reverse by dotted path, e.g. reverse('myapp.views.myview')
.
Marc mentioned in that ticket "Reversing by dotted path to view is just a bad idea."
Change History (15)
comment:1 by , 11 years ago
comment:4 by , 11 years ago
I agree that reversing by dotted-path-to-view is "a bad idea". I would even say it's just ridiculous, and I didn't even knew it existed. Obviously you should just use the url name. What would actually happen when you have two urls to the same view? Anyway, I'm all for deprecating that feature.
On the other hand, I'm not entirely convinced about deprecating the dotted-path-to-view in url feature. There are a lot of settings and other things in Django which work that way, and it's a nice feature which prevents the imports from cluttering for the people who are still pro FBV's. Unless it opens up the possibility of removing the necessity of calling as_view()
on every CBV in the urls. If deprecating this feature is part of a bigger plan to migrate to cleaner urls for CBV's, then I'm all for it.
comment:5 by , 11 years ago
+1 from me. Are there any use cases where someone needs the string version in urls.py
to avoid a circular imports problem? Not that I can think of, but I thought I'd mention it...
comment:6 by , 10 years ago
Gwildor, the feature pre-dates named url patterns [yes, there wasn't always that feature].
Also, as I'm sure Alex will point out, it can make debugging harder, as the error of a wrong import won't always show up, and will appear to come from the wrong place when it does fire off.
This will have no impact on needing to call as_view on CBV. The as_view method is a view function factory -- it is what makes the actual view function used to invoke the CBV... you can't do without it.
comment:7 by , 10 years ago
Has patch: | set |
---|---|
Summary: | Deprecate Django string magic in URLs and the ability to reverse by dotted path → Deprecate the ability to reverse by dotted path |
I've reduced the scope of this ticket to only deprecating the ability to reverse by dotted path (instead of also removing the "string magic" in url()
). I'll save that bit for a future ticket.
Pull request is up for review.
comment:8 by , 10 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
I left some comments on the PR. Except the doc issue it looks RFC.
comment:9 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I plan to work on this, but will wait to ensure that there are no -1's to the idea, raising it on the mailing list if necessary.