开发者

Learning pyramid (python) and am struggling with the @view_config decorator. Should it just work out of the box?

开发者 https://www.devze.com 2023-03-02 02:11 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号