On Thu, Jun 16, 2011 at 10:03 AM, AwaisMuzaffar <awais1...@googlemail.com>wrote:
> config.add_route('ajax', '/ajax/', view='testproject.views.ajax') > > def ajax(request): > string = 'hello world' > return Response(string) > This is fine, but there are 2 enhancements you may want to use in your Pyramid code. First, if you want to expand your interface to be more restful in the future, you may want to separate your config using predicates to match POST requests to certain views and GET requests to other views. The other thing is that you can utilize Pyramid's renderers to avoid having to return a full Response object yourself. As an example, set the renderer to 'json' (or if you do it in add_route then it's the view_renderer). config.add_route('ajax', '/ajax') config.add_view(route_name='ajax', view='testproject.views.ajax', request_method='POST', renderer='json') >From your view code you can then: return 'hello world' and it will be json serialized for you. -- Michael -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.