Opened 8 years ago

Closed 8 years ago

Last modified 8 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 Changed 8 years ago by Thomas Güttler

Description: modified (diff)

comment:2 Changed 8 years ago by Claude Paroz

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 Changed 8 years ago by Tim Graham

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 Changed 8 years ago by Thomas Güttler

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 Changed 8 years ago by Tim Graham

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 Changed 8 years ago by Alvin Mites

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 Changed 8 years ago by Wim Feijen

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 Changed 8 years ago by Aymeric Augustin

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 Changed 8 years ago by Thomas Güttler

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 Changed 8 years ago by Aymeric Augustin

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 Changed 8 years ago by Thomas Güttler

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 Changed 8 years ago by Aymeric Augustin

Exactly. Sorry for not expressing that clearly.

comment:13 Changed 8 years ago by gayathri Menakath

Owner: changed from nobody to gayathri Menakath
Status: newassigned

comment:14 Changed 8 years ago by gayathri Menakath

Cc: gayathri Menakath added

comment:15 Changed 8 years ago by Elena Oat

Owner: changed from gayathri Menakath to Elena Oat

comment:16 Changed 8 years ago by Elena Oat

Owner: Elena Oat deleted
Status: assignednew

comment:17 Changed 8 years ago by thijsvandien

Owner: set to thijsvandien
Status: newassigned

comment:18 Changed 8 years ago by thijsvandien

Has patch: set

comment:19 Changed 8 years ago by Tim Graham <timograham@…>

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 Changed 8 years ago by Tim Graham <timograham@…>

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 Changed 8 years ago by Tim Graham <timograham@…>

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