#25473 closed Cleanup/optimization (fixed)
Consistently use dashes instead of underscores in URL names
Reported by: | Thomas Güttler | Owned by: | thijsvandien |
---|---|---|---|
Component: | Documentation | Version: | 1.8 |
Severity: | Normal | Keywords: | |
Cc: | gayathri Menakath | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
Please use one form to refer to the update-view of
a model.
Here are two: 'author-detail' vs 'author_update'
def get_absolute_url(self): return reverse('author-detail', kwargs={'pk': self.pk})
from https://docs.djangoproject.com/en/1.8/topics/class-based-views/generic-editing/#model-forms
some lines below the above link:
url(r'author/(?P<pk>[0-9]+)/$', AuthorUpdate.as_view(), name='author_update'),
But first: The django core developers should decide which pattern should be used in the docs:
foo-detail or foo_update.
When the decision was made, then all examples in the docs should use this pattern.
Change History (21)
comment:1 by , 9 years ago
Description: | modified (diff) |
---|
comment:2 by , 9 years ago
comment:3 by , 9 years ago
It looks to me like the complaint is that sometimes dashes are used in url()
names, sometimes underscores. If I had to cast a vote, I guess I'd choose dashes based on Google's advice "We recommend that you use hyphens (-) instead of underscores (_) in your URLs." and the fact that you might want your URL names to roughly match the URLs themselves.
comment:4 by , 9 years ago
Yes, this ticket is not about technical details, it is about the Zen of Python:
"There should be one-- and preferably only one --obvious way to do it."
It least the django docs should be consistently use hyphens xor underscore for url names.
comment:5 by , 9 years ago
Easy pickings: | set |
---|---|
Summary: | Docs: 'author-detail' vs 'author_update' → Consistently use dashes instead of underscores in URL names |
Triage Stage: | Unreviewed → Accepted |
Note that we cannot change some examples like url(r'^reset/done/$', auth_views.password_reset_complete, name='password_reset_complete')
in docs/ref/contrib/admin/index.txt
as Django templates use those names in templates.
comment:6 by , 9 years ago
or perhaps the scope of this ticket could be expanded to include updating the bundled templates
perhaps add a DEPRECATED / duplicate of urlpatterns that include all the old underscore naming?
comment:7 by , 9 years ago
Hi guys,
My preference would be to use underscores in stead of dashes, because we are coupling urls to views, and in function based views, view names always use underscores instead of dashes.
My personal preference is to have url names, view names and template names the same, all using underscores.
My url patterns tend to differ anyway, containing dashes, slug regexes and such.
comment:8 by , 9 years ago
The counter-argument is that using a different convention for different types of objects makes it easier to search or replace one type and not the others.
comment:9 by , 9 years ago
What kind of types do you have? Can you please list some. I could guess what you mean, but I don't like guessing.
comment:10 by , 9 years ago
Here are the three conventions and the types they're commonly used for:
dash-separated
: URL namesunderscore_separated
: FBV function namesCamelCase
: CBV class names and other classes: models, forms, etc.
comment:11 by , 9 years ago
You wrote "The counter-argument is that using a different convention for different types of objects makes it easier to search or replace one type and not the others."
I understood that there are different types of url-names. But that was my mistake.
I guess I understood you now: You want dash-seperated of the url names, since .. it makes it easier to search or replace one type and not the others. Correct?
comment:13 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:14 by , 9 years ago
Cc: | added |
---|
comment:15 by , 9 years ago
Owner: | changed from | to
---|
comment:16 by , 9 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:17 by , 9 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:18 by , 9 years ago
Has patch: | set |
---|
Pull request at https://github.com/django/django/pull/5593
Can you please clarify what is the precise object of this ticket? Is this the hyphen vs underscore in the view name? Because detail and update views are different views...