Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#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 Thomas Güttler)

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 Thomas Güttler, 9 years ago

Description: modified (diff)

comment:2 by Claude Paroz, 9 years ago

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...

comment:3 by Tim Graham, 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 Thomas Güttler, 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 Tim Graham, 9 years ago

Easy pickings: set
Summary: Docs: 'author-detail' vs 'author_update'Consistently use dashes instead of underscores in URL names
Triage Stage: UnreviewedAccepted

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 Alvin Mites, 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 Wim Feijen, 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 Aymeric Augustin, 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 Thomas Güttler, 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 Aymeric Augustin, 9 years ago

Here are the three conventions and the types they're commonly used for:

  • dash-separated: URL names
  • underscore_separated: FBV function names
  • CamelCase: CBV class names and other classes: models, forms, etc.

comment:11 by Thomas Güttler, 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:12 by Aymeric Augustin, 9 years ago

Exactly. Sorry for not expressing that clearly.

comment:13 by gayathri Menakath, 9 years ago

Owner: changed from nobody to gayathri Menakath
Status: newassigned

comment:14 by gayathri Menakath, 9 years ago

Cc: gayathri Menakath added

comment:15 by Elena Oat, 9 years ago

Owner: changed from gayathri Menakath to Elena Oat

comment:16 by Elena Oat, 9 years ago

Owner: Elena Oat removed
Status: assignednew

comment:17 by thijsvandien, 9 years ago

Owner: set to thijsvandien
Status: newassigned

comment:18 by thijsvandien, 9 years ago

Has patch: set

comment:19 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 16794721:

Fixed #25473 -- Changed underscores in url() names to dashes in docs.

To improve consistency, sample URL names that had underscores
in them now use dashes instead. That excludes URL names that
have some relation to the code, such as those generated by
the admin.

Thanks guettli for reporting this.

comment:20 by Tim Graham <timograham@…>, 9 years ago

In f5e1d72:

[1.9.x] Fixed #25473 -- Changed underscores in url() names to dashes in docs.

To improve consistency, sample URL names that had underscores
in them now use dashes instead. That excludes URL names that
have some relation to the code, such as those generated by
the admin.

Thanks guettli for reporting this.

Backport of 1679472165e840aef4c8c9ece2fbf4620b87beab from master

comment:21 by Tim Graham <timograham@…>, 9 years ago

In 78a28cca:

[1.8.x] Fixed #25473 -- Changed underscores in url() names to dashes in docs.

To improve consistency, sample URL names that had underscores
in them now use dashes instead. That excludes URL names that
have some relation to the code, such as those generated by
the admin.

Thanks guettli for reporting this.

Backport of 1679472165e840aef4c8c9ece2fbf4620b87beab from master

Note: See TracTickets for help on using tickets.
Back to Top