Opened 11 years ago

Closed 11 years ago

Last modified 11 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: no UI/UX: no


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:

$ ./ 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.
>>> 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/", 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/", line 226, in reverse
    possibilities, pattern = self.reverse_dict.get(lookup_view, [(), ()])
  File "/usr/lib/python2.4/site-packages/django/core/", line 160, in _get_reverse_dict
    for name, (matches, pat) in pattern.reverse_dict.iteritems():
  File "/usr/lib/python2.4/site-packages/django/core/", line 160, in _get_reverse_dict
    for name, (matches, pat) in pattern.reverse_dict.iteritems():
  File "/usr/lib/python2.4/site-packages/django/core/", line 168, in _get_reverse_dict
    self._reverse_dict[pattern.callback] = bits, p_pattern
  File "/usr/lib/python2.4/site-packages/django/core/", 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.

Change History (5)

comment:1 Changed 11 years ago by Malcolm Tredinnick

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 11 years ago by keizie

page/ 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 11 years ago by Alex Gaynor

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 11 years ago by Malcolm Tredinnick

Resolution: invalid
Status: newclosed

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 11 years ago by keizie

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

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