[Django]-Django Testing Framework with login decorators – do they work? Error with reverse

7👍

The error log reported there tells you most of what you need to know:

First you’ve got:

in test_main
        response = c.get('/', follow=True)

Which means it’s dying while trying to process that request. Next:

      File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/test/client.py", line 281, in get
 [...]
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/template/__init__.py", line 792, in render_node
        return node.render(context)

It’s dying while rendering a node in the template, which means it’s getting to the template, not dying at the login. Last:

      File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/template/defaulttags.py", line 382, in render
        raise e
    NoReverseMatch: Reverse for '<django.contrib.auth.decorators._CheckLogin object at 0x22d4650>' with arguments '()' and keyword arguments '{'report_type': u'this_week'}' not found.

It’s raising an exception while trying to reverse a url in your template, which means you called the {% url %} tag somewhere with the path to your view function and the argument “this_week”, but that’s not the appropriate way to call your view function according to your URLconf.

Fix your {% url %} tag or your view function definition and it’ll work.

1👍

Did you check your regex’s in urls.py? Maybe the are bogus.

Also check this Bug Ticket Reverse for ‘<django.contrib.auth.decorators._CheckLogin object at 0x8ee144c>’ not found

Btw. this is what the django source-code says around line 382 in defaulttags.py

# Try to look up the URL twice: once given the view name, and again
# relative to what we guess is the "main" app. If they both fail,
# re-raise the NoReverseMatch unless we're using the
# {% url ... as var %} construct in which cause return nothing.
👤jitter

-2👍

Do you have LOGIN_URL defined in your settings.py file?

👤emeryc

Leave a comment