Code

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#8854 closed (invalid)

url tag and reverse function do not work

Reported by: keizie Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

urls.py

from django.conf.urls.defaults import *
from tagging.models import Tag

urlpatterns = patterns('tagging.views',
    (r'^tag/(?P<tag>\w+)/', 'tagged_object_list', {'queryset_or_model':Tag, 'related_tags':True}),
)
urlpatterns += patterns('page.views',
    (r'^$', 'show'),
    (r'^rev/(?P<rev>\w+)/', 'show'),
    (r'^diff/(?P<old>\s+)/(?P<new>\s+)/', 'diff'),
    (r'^edit/', 'edit'),
    (r'^info/', 'info'),
    (r'^delete/', 'delete'),

    url(r'^recent/', 'recent', name='recent'),
    (r'^search/((?P<needle>\s+)/)?', 'search'),
    (r'^tag/', 'tag'),

    (r'^(?P<action>\w+)/', 'unknown'),
)

And try:

$ ./manage.py shell
Python 2.4.3 (#1, May 24 2008, 13:47:28) 
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.urlresolvers import reverse
>>> reverse('recent')
Traceback (most recent call last):
  File "<console>", line 1, in ?
  File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py", line 249, in reverse
    return iri_to_uri(u'%s%s' % (prefix, get_resolver(urlconf).reverse(viewname,
  File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py", line 226, in reverse
    possibilities, pattern = self.reverse_dict.get(lookup_view, [(), ()])
  File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py", line 160, in _get_reverse_dict
    for name, (matches, pat) in pattern.reverse_dict.iteritems():
  File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py", line 160, in _get_reverse_dict
    for name, (matches, pat) in pattern.reverse_dict.iteritems():
  File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py", line 168, in _get_reverse_dict
    self._reverse_dict[pattern.callback] = bits, p_pattern
  File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py", line 135, in _get_callback
    raise ViewDoesNotExist, "Tried %s in module %s. Error was: %s" % (func_name, mod_name, str(e))
ViewDoesNotExist: Tried delete in module page.views. Error was: 'module' object has no attribute 'delete'
>>> 

Even admin page breaks with url template tag, like {% url django-admindocs-docroot as docsroot %}.

r8759 and r8934 tested.

Attachments (0)

Change History (5)

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Do you have a delete() method in your page.views module? If not, that's the problem. Your URLConf file must be valid for reverse() to work.

comment:2 Changed 6 years ago by keizie

page/views.py have no def delete().

Do you mean that each view module have to implement delete method to be integrated with reverse()?
But 'URL dispatcher' of documentation don't mention that delete() method is necessary.

comment:3 Changed 6 years ago by Alex

No, but each reference to a view must be valid, you have a view named delete, for reverse to work that function needs to exist.

comment:4 Changed 6 years ago by mtredinnick

  • Resolution set to invalid
  • Status changed from new to closed

If you're still having trouble with this, please ask on the django-users mailing list. There's no bug in Django here.

comment:5 Changed 6 years ago by keizie

Oops. Just found what I've missed between urls and views. Sorry to bother you.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.