Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#6472 closed (invalid)

reverse() fails when used outside of a view function

Reported by: floguy Owned by: nobody
Component: Uncategorized 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

Given a simple urls file:

from django.conf.urls.defaults import *
import views

urlpatterns = patterns('',
    url('myview', views.my_view, name="myview_named"),
)

...and a simple view function:

from django.http import HttpResponse
from django.core.urlresolvers import reverse

def my_view(request):
    my_view_url = reverse('myview_named') # This works
    return HttpResponse('Hello from my_view.')

my_view_url = reverse('myview_named') # This does not work.

Using reverse() inside the view works correctly, but in the global scope of the views file (as is very nice for a login_url argument to a decorator, for example) it fails with some very strange errors.

Change History (3)

comment:1 by James Bennett, 17 years ago

Using reverse() inside the view works correctly, but in the global scope of the views file (as is very nice for a login_url argument to a decorator, for example) it fails with some very strange errors.

And unless you tell us what those errors are, nobody will be able to help you track them down.

comment:2 by Chris Beaven, 17 years ago

Resolution: invalid
Status: newclosed
Triage Stage: UnreviewedSomeday/Maybe

Needs more info. But I'd guess that it's due to the circular nature of importing the view in the URLconf.

comment:3 by Chris Beaven, 17 years ago

Triage Stage: Someday/MaybeUnreviewed
Note: See TracTickets for help on using tickets.
Back to Top