0

I think I've looked almost all the examples in google to solve the issue, but still can't get it working well.

My goal is to request data from server after clicking on a button.
The error I get at this moment:

Traceback (most recent call last):
  File "/opt/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1546, in __call__
    return response(environ, start_response)
TypeError: 'str' object is not callable
INFO     2015-01-04 22:16:52,235 module.py:709] default: "POST /nearest_banks/radius HTTP/1.1" 500 662

My code:

ajax function:

<script type="text/javascript">
    $( "#yes" ).click(function() {
        $( "#ask_user" ).hide();
        $.ajax({
            type: "post",
            url: '/nearest_banks/radius',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
           // data: { 'names': {{names}}, 'location': {{location}} },
            success: function (output) {
                output = JSON.parse(output);
                ("#places").empty();
                output.forEach(function (names) {
                    var $row = $('<p>').appendTo("#places");
                });
            }});
    });
</script>

Python function:

def post(self):
        names, location, telephone, check = funcs.Findplaces(default_radius)  
        dict = {'names': names, 'location': location}
        output = json.dumps(dict)
        return output
  • function Findplaces works well. It returns names, location etc the right way in Unicode type.

These are my urls:

application = webapp2.WSGIApplication([
   webapp2.Route(r'/', handler=MainPage, name='mpage', handler_method='get'),
   webapp2.Route(r'/nearest_banks', handler=Nearest_banks, name='ne_banks', handler_method='main_func'),
   #webapp2.Route(r'/nearest_banks/radius', handler=Nearest_banks, name='ne_banks', handler_method='get'),
   webapp2.Route(r'/nearest_banks/radius', handler=Nearest_banks, name='radius', handler_method='post'),
], config=session_module.config, debug=True)

As I understand the error is in the Python def post function .. Please, help me someone to cope with it ...

All I need is to get data from server and show it in some tag on page...

1
  • You must avoid using keywords like dict as variable names, as these override the in-built objects and giving rise to many problems,I don't guess you are facing same issues over here, But just for the sake of good programming practice. Commented Jan 5, 2015 at 6:37

1 Answer 1

2

See http://webapp-improved.appspot.com/guide/handlers.html#returned-values

A handler method doesn't need to return anything: it can simply write to the response object using self.response.write().

But a handler can return values to be used in the response. Using the default dispatcher implementation, if a handler returns anything that is not None it must be a webapp2.Response instance. If it does so, that response object is used instead of the default one.

Your post() handler is now returning a string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.