Django

Code

Ticket #4129 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

Named urls break view prefix.

Reported by: justin.driscoll@gmail.com Assigned to: adrian
Milestone: Component: Core framework
Version: SVN Keywords: named, urls, view, prefix
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

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

5079-patch_for_url_and_prefix.diff (2.0 kB) - added by Michael Axiak <axiak@mit.edu> on 04/26/07 03:34:46.
My crack at a fix for this bug.
5079-patch_for_url_and_prefix_2.diff (2.0 kB) - added by Michael Axiak <axiak@mit.edu> on 04/26/07 03:38:12.
I had a typo.

Change History

(follow-up: ↓ 2 ) 04/23/07 09:51:51 changed by mtredinnick

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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?

(in reply to: ↑ 1 ) 04/23/07 09:57:48 changed 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.

04/23/07 11:10:37 changed by Gary Wilson <gary.wilson@gmail.com>

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.

04/23/07 11:18:28 changed by justin.driscoll@gmail.com

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.

04/23/07 22:34:37 changed by Gary Wilson <gary.wilson@gmail.com>

  • stage changed from Unreviewed to Design decision needed.

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

04/24/07 01:55:59 changed by mtredinnick

  • stage changed from Design decision needed to Accepted.

This is just a bug. No discussion required.

04/26/07 03:34:46 changed by Michael Axiak <axiak@mit.edu>

  • attachment 5079-patch_for_url_and_prefix.diff added.

My crack at a fix for this bug.

04/26/07 03:38:12 changed by Michael Axiak <axiak@mit.edu>

  • attachment 5079-patch_for_url_and_prefix_2.diff added.

I had a typo.

(follow-up: ↓ 8 ) 04/26/07 03:39:29 changed by Michael Axiak <axiak@mit.edu>

  • needs_better_patch set to 1.
  • has_patch set to 1.

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

(in reply to: ↑ 7 ) 04/26/07 06:16:10 changed by mtredinnick

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.

04/26/07 06:17:19 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #4129 (Named urls break view prefix.)




Change Properties
Action