Opened 8 years ago

Closed 8 years ago

#7768 closed (duplicate)

r 'str' object is not callable in

Reported by: William Martinez Pomares <wmartinez@…> Owned by: nobody
Component: Core (Other) 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 (last modified by Adrian Holovaty)

Working with SVN revision 7930, following the tutorial, up to the place where the votes view is created.
The line in the vote() method

   return HttpResponseRedirect(reverse('mysite.polls.views.results', args=(,)))

fails presenting a debug page that says:

TypeError at /polls/1/results/
'str' object is not callable
Request Method: 	GET
Request URL:
Exception Type: 	TypeError
Exception Value: 	'str' object is not callable
Exception Location: 	C:\Python25\lib\site-packages\django\core\handlers\ in get_response, line 85

I have found some relates issues (like 4700) that point to the INSTALLED_APPS settings and how the django.contrib.auth affects the get_response. I tried eliminating that application and still the error shows.
If using HttpResponseRedirect without the reverse (hardcoding the url) it fails too. If using render_to_response() instead, it works.

Another relate ticket may be 6442, but that one happens when the import error occurs. In this case the imports are ok in, it is the HttpResponseRedirect that may have problems.

William Martinez.

Change History (12)

comment:1 Changed 8 years ago by William Martinez Pomares <wmartinez@…>

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

An update.

I found out a problem in the, the actual results() method that is the one called when HttpResponseRedirect is executed (url is '/polls/3/results/'). It had a problem in the name, so it was not found. That may not cause an import issue like in ticket 6442 but it will probably raise an exception. I was about to set this ticket as a duplicaet of 6442, but it is slightly different in the cause. Still, it may be resolved around the same command line.

Here, as in 6442, the error should indicate the view was not found instead of the misleading TypeError at


comment:2 Changed 8 years ago by Adrian Holovaty

Description: modified (diff)

(Fixed formatting in description)

comment:3 Changed 8 years ago by Eric Holscher

Resolution: worksforme
Status: newclosed

Ask on django-users, more than likely the tutorial is correct.

comment:4 in reply to:  3 Changed 8 years ago by bengan

Resolution: worksforme
Status: closedreopened

Replying to ericholscher:

Ask on django-users, more than likely the tutorial is correct.

But not for me. I have the same issue. Exactly the same.

comment:5 Changed 8 years ago by James Bennett

Resolution: worksforme
Status: reopenedclosed

The tutorial is correct; if you read the comments above you'll see that the original person who filed this ticket had an error of his own while following the tutorial, rather than an error due to the code in the tutorial. As Eric suggested, ask on django-users for further help rather than needlessly churning the ticket tracker.

comment:6 Changed 8 years ago by William Martinez <wmartinez@…>

I'm the original person that wrote the ticket. It is NOT a tutorial problem I talked about, so this is not a django-users question.
Please read carefully:

In following the tutorial, I wrote something wrong, so it was supposed to fail.
I expected to see an error of method or view not found. Instead I saw another error, the one " 'str' object not callable' at
Following other bugs, it seems it actually raise an exception that is caught and ignored, leading to an error later on at
Bug 6442 explains this.

So, in summary:
-> If you have a typo in the view method, it will not tell you that. It will throw a misleading exception " 'str' object not callable' at
THAT, is the bug.

I won't reopen the ticket, if you fix bug 6442 it may get fixed.
William Martinez.

comment:7 Changed 8 years ago by hannnndy <web@…>

Resolution: worksforme
Status: closedreopened
Summary: HttpResponseRedirect causes a TypeError 'str' object is not callable in base.pyr 'str' object is not callable in

why this error happens and how should i solve it

comment:8 Changed 8 years ago by dc

Resolution: worksforme
Status: reopenedclosed

Please ask on django-users for help.

comment:9 Changed 8 years ago by Karen Tracey

Replying to hannnndy <>:

why this error happens and how should i solve it

I don't know, because you have provided no information about what you are doing. The reported instances of this error are all user error, so tracking down what is going wrong is best done on django-users, where there are more people reading and likely to help, than in the ticket tracker. Or read through the comments here and in #6442 and see if you have made an error similar to others that led to this error message. The bug in Django here is that this error message is not very helpful in tracking down what your real error is, and that is covered by #6442.

comment:10 Changed 8 years ago by ziofunk

Resolution: worksforme
Status: closedreopened

comment:11 Changed 8 years ago by ziofunk

The same wrong error message is returned in a situation that is not described in #6442.
I have an inside my application. I have it correctly included in the project When I use the first argument to the patterns() function to specify a prefix to be applied to each view function, if the prefix is mispelled I get the correct error saying that the module does not exist. When I don't put any prefix I get the wrong error message reported in this bug:

Exception Value: 'str' object is not callable
Exception Location: C:\Python25\lib\site-packages\django\core\handlers\ in get_response, line 85

comment:12 Changed 8 years ago by Karen Tracey

Resolution: duplicate
Status: reopenedclosed

While your exact reproduction scenario may differ from what is detailed in #6442, it sounds to me like the fix proposed for #6442 would cover this case as well. The fix suggested there is:

"I suggest that urlresolver would raise an exception on invalid look-ups."

If that fix were in place, then the resolve() call would raise an error instead of returning a string, and you'd never get to the point where subsequent code tried to call a string object.

So I'd say your scenario is just a different way of tripping over the same bug -- you just have a different way of injecting an invalid lookup into your If you'd like to ensure your case is considered when #6442 is fixed, the right place to mention it is in #6442 itself, not here. We only need one open ticket to track improving this error situation.

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