Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#8854 closed (invalid)

url tag and reverse function do not work

Reported by: keizie Owned by: nobody
Component: Core (Other) Version: dev
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

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.

Change History (5)

comment:1 by Malcolm Tredinnick, 16 years ago

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

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 by Alex Gaynor, 16 years ago

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

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

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