Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#6472 closed (invalid)

reverse() fails when used outside of a view function

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

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 Changed 8 years ago by ubernostrum

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

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 Changed 8 years ago by SmileyChris

  • Resolution set to invalid
  • Status changed from new to closed
  • Triage Stage changed from Unreviewed to Someday/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 Changed 8 years ago by SmileyChris

  • Triage Stage changed from Someday/Maybe to Unreviewed
Note: See TracTickets for help on using tickets.
Back to Top