首页 > 解决方案 > Turbogears: multiple rendering the same method code for different HTML templates

问题描述

I would like to render in different way (using different HTML template) the same method code. I know that I can use "Inherit" parameter in @expose decorator to do this once https://turbogears.readthedocs.io/en/latest/turbogears/objectdispatch.html#subclassing-controllers

Based on example from turbogears code I would like do this multiple times for "about" method

class OriginalController(TGController):
     @expose('mylib.templates.index')
     def index(self):
        return dict()

    @expose('mylib.templates.about')
    def about(self):
        return dict()


class MyCustomizedController(OriginalController):
    @expose(inherit=True)
    def index(self, *args, **kw):
        dosomething()
        return super(MyCustomizedController, self).index(*args, **kw)

    @expose('myapp.templates.newabout', inherit=True)
    def about(self):
        return super(MyCustomizedController, self).about(*args, **kw)


    @expose('myapp.templates.newabout2', inherit=True)
    def about2(self):
        return super(MyCustomizedController, self).about(*args, **kw)


    @expose('myapp.templates.newabout3', inherit=True)
    def about3(self):
        return super(MyCustomizedController, self).about(*args, **kw)

How can I do this in a best way? Is this code above correct to do this?

标签: pythoncontrollerturbogears2

解决方案


推荐阅读