Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#13398 closed (invalid)

reverse() causes exception if run in views.py, outside of a view.

Reported by: cbarnell 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

Running reverse('my_url_conf_name') inside of views.py will raise ViewDoesNotExist exception.

Example:

# myproject.apps.someapp.views.py
from django.core.urlresolvers import reverse

foo_url = reverse('foo_view')

def spam_view():
    return HttpResponse('Hello World')


# Running any view in this module will raise something like:
# "Tried spam_view in module myproject.apps.someapp.views. Error was: 'module' object has no attribute 'spam_view'"
# Notice that 'spam_view' isn't even the view I passed in, and in fact if I delete the call to reverse() I can visit the 'spam_view' and it works fine.
# If I put the call to reverse('foo_view') inside of a view, and visit that view to render the url out to a page, it works just fine.

Change History (3)

comment:1 Changed 5 years ago by cbarnell

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

Update: Whatever views.py module you do this in, the exception will state the last view in that module.

comment:2 Changed 5 years ago by cbarnell

  • Resolution set to invalid
  • Status changed from new to closed

Oops.

comment:3 Changed 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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