#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 , 17 years ago
comment:2 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Triage Stage: | Unreviewed → 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 by , 17 years ago
Triage Stage: | Someday/Maybe → Unreviewed |
---|
Note:
See TracTickets
for help on using tickets.
And unless you tell us what those errors are, nobody will be able to help you track them down.