python - 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?
解决方案
推荐阅读
- python-3.x - Python中的IPv4Network - 计算不同大小的下一个最小子网?
- email - 阻止来自 Sendgrid 的垃圾邮件
- javascript - 如何在javascript中隐藏以前的div?
- python - 创建键盘快捷键以使用 pynput 和 pywin32 发送电子邮件
- javascript - 需要使子菜单全屏
- android - Signal-r android 在 iis express 上工作,但不在 windows server 2019 上的 iis 10 中
- python - 如何获取 Python 函数中定义的局部变量?
- javascript - 使用 javascript 显示动态 youtube 视频
- javascript - 反应原生:模态总是可见的
- c# - C# 将参数附加到字符串