Learning pyramid (python) and am struggling with the @view_config decorator. Should it just work out of the box?
I am still learning pyramid, and I am at a point where I am trying to learn how to use decorators. Below is a copy of my test view callable.
from pyramid.response import Response
from pyramid.view import view_config
from pyramid.renderers import render_to_response
def my_blog(request):
return {'project':'tricky'}
@view_config( renderer='templates/foo.pt' )
def foo_blog(request):
return {'name':'tricky'}
From what I can understand about the view_config decorator, it can be used to set application configurations without actually setting them in the config file. In the case of this example, I am setting the renderer to be templates/foo.pt. This does not ever work.
However, if I set renderer in the config file (init.py) as such:
config.add_route( 'foo_blog' , '/blog/{foo}' , view='tricky.views.Blog.blog.foo_blog' renderer='tricky:templates/mytemplate.pt' )
it will work.
Am开发者_StackOverflow社区 I doing something wrong that is preventing me from being able to use the decorator. Thanks!
In order for the configurations added via @view_config to work, you need to call config.scan() at some point.
精彩评论