On Tue, 2012-02-28 at 09:25 -0800, Ben Sizer wrote:
> Here's my code (JSON function copied from
> http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/renderers.html,
> and the rest from the Hello World):
> 
> 
>     from wsgiref.simple_server import make_server
>     from pyramid.config import Configurator
>     from pyramid.view import view_config
> 
>     @view_config(renderer='json')
>     def hello_world(request):
>         return {'content':'Hello!'}
> 
>     if __name__ == '__main__':
>         config = Configurator()
> 
>         config.add_route('create_account', '/create')
>         config.add_view(hello_world, route_name='create_account')
> 
>         app = config.make_wsgi_app()
>         server = make_server('0.0.0.0', 8080, app)
>         server.serve_forever()
> 
> 
> Here's what happens when I visit /create:
> 
> 
> Traceback (most recent call last):
>   File "C:\Python27\lib\wsgiref\handlers.py", line 85, in run
>     self.result = application(self.environ, self.start_response)
>   File "C:\Python27\lib\site-packages\pyramid\router.py", line 187, in
> __call__
>     response = self.handle_request(request)
>   File "C:\Python27\lib\site-packages\pyramid\tweens.py", line 20, in
> excview_tween
>     response = handler(request)
>   File "C:\Python27\lib\site-packages\pyramid\router.py", line 164, in
> handle_request
>     response = view_callable(context, request)
>   File "C:\Python27\lib\site-packages\pyramid\config\views.py", line
> 371, in viewresult_to_response
>     raise ValueError(msg % (view_description(view), result))
> ValueError: Could not convert return value of the view callable
> function __main__.hello_world into a response object. The value
> returned was {'content': 'Hello!'}. You may have forgotten to define a
> renderer in the view configuration.
> 
> 
> But the renderer's right there, copied from the docs...
> 
> Any idea what is wrong?

You can't mic view_config with add_view.  Instead use view_config with a
scan:

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.view import view_config

@view_config(renderer='json', route_name='create_account')
def hello_world(request):
    return {'content':'Hello!'}

if __name__ == '__main__':
    config = Configurator()

    config.add_route('create_account', '/create')
    config.scan()

    app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 8080, app)
    server.serve_forever()


> 
> --
> Ben Sizer
> 
> 
> 
> 
> 


-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.

Reply via email to