Calling another view in Pyramid

前端 未结 6 1400
庸人自扰
庸人自扰 2021-02-02 16:02

My goal: In Pyramid, to call another view-callable, and to get a Response object back without knowing any details about that view-callable.

In my Pyramid a

6条回答
  •  有刺的猬
    2021-02-02 16:42

    Not the precise solution you asked for, but a solution to the problem you describe:

    Create a view class, of which both foo and bar are methods. Then bar can call self.foo()

    Common view_configuration, such as the template name can be applied to the class, and then you can decorate each method with just the view name.

    In short, the following should meet your needs, if I understand the problem correctly.

    @view_defaults(renderer="foo.jinja2")
    class WhereaboutsAreFoo(object):
    
        @view_config(route-name="foo")
        def foo_view(self):
            return {"whereami" : "foo!"}
    
        @view_config(route-name="bar")
        def bar_view(self):
            return self.foo_view()
    

提交回复
热议问题