Opened 10 years ago

Closed 10 years ago

#4129 closed (fixed)

Named urls break view prefix.

Reported by: justin.driscoll@… Owned by: Adrian Holovaty
Component: Core (Other) Version: master
Severity: Keywords: named, urls, view, prefix
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

The following code results in a ViewDoesNotExist exception for 'archive_index' (assuming "info_dict" contains the needed parameters):

urlpatterns = patterns('django.views.generic.date_based',
    url(r'^articles/?$', 'archive_index', info_dict, name="article-archive-index")
)

This works fine:

urlpatterns = patterns('',
    url(r'^articles/?$', 'django.views.generic.date_based.archive_index', info_dict, name="article-archive-index")
)

View prefixes do not seem to work for custom views either when used in conjunction with named urls.

Attachments (2)

5079-patch_for_url_and_prefix.diff (2.0 KB) - added by Michael Axiak <axiak@…> 10 years ago.
My crack at a fix for this bug.
5079-patch_for_url_and_prefix_2.diff (2.0 KB) - added by Michael Axiak <axiak@…> 10 years ago.
I had a typo.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 10 years ago by Malcolm Tredinnick

What do you have to do to cause this error? You explain what error is raised, but what are you doing when it is raised -- using reverse()? Doing a normal url lookup? Other?

comment:2 in reply to:  1 Changed 10 years ago by anonymous

Replying to mtredinnick:

What do you have to do to cause this error? You explain what error is raised, but what are you doing when it is raised -- using reverse()? Doing a normal url lookup? Other?

The error is raised when accessing the URL normally. I have not tested doing a reverse lookup as the primary functionality seems to be broken.

comment:3 Changed 10 years ago by Gary Wilson <gary.wilson@…>

You will see this error if you try performing a normal URL lookup by browsing to .../articles/ since the prefix parameter from the patterns() call doesn't get passed along to the the url() call. The prefix only gets passed along when using url conf tuples.

comment:4 Changed 10 years ago by justin.driscoll@…

Is that the intended functionality that url prefixes and named urls are incompatible? If so, it should be reflected in the documentation. Right now the docs show the url prefix empty but make no mention of it not working with the url() function. I haven't looked at the source yet, and do not know the complexity involved, but I would like to see the two play nicely together.

comment:5 Changed 10 years ago by Gary Wilson <gary.wilson@…>

Triage Stage: UnreviewedDesign decision needed

You might want to start a discussing about it on the django-dev mailing list.

comment:6 Changed 10 years ago by Malcolm Tredinnick

Triage Stage: Design decision neededAccepted

This is just a bug. No discussion required.

Changed 10 years ago by Michael Axiak <axiak@…>

My crack at a fix for this bug.

Changed 10 years ago by Michael Axiak <axiak@…>

I had a typo.

comment:7 Changed 10 years ago by Michael Axiak <axiak@…>

Has patch: set
Patch needs improvement: set

Added a patch that will probably fix the bug. Setting the 'Patch needs improvement' flag until someone deems it a good patch.

comment:8 in reply to:  7 Changed 10 years ago by Malcolm Tredinnick

Replying to Michael Axiak <axiak@mit.edu>:

Added a patch that will probably fix the bug. Setting the 'Patch needs improvement' flag until someone deems it a good patch.

Your patch would have fixed the problem. It looks fine.

In the end, I've fixed this in a very slightly different fashion so that the internal _callable_str variable doesn't leak out of the !RegexURLPattern class. But thanks for the patch anyway.

comment:9 Changed 10 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [5086]) Fixed #4129 -- Pass any prefix setting into url(...) constructions so that
prefixes work with the new syntax and strings for function names.

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