Python 从一个视图委派到另一个视图

Python 从一个视图委派到另一个视图,python,pyramid,Python,Pyramid,我用的是不同视角的金字塔。我想知道是否有可能将视图作业的一部分“委派”给另一个视图(另一条路线) 例如: http://localhost:6543/sample_project/testruns/testrun001/report.html?action=edit => delegate to: http://localhost:6543/sample_project/testruns/testrun001/report.json 我使用的视图包括: # report: @view_c

我用的是不同视角的金字塔。我想知道是否有可能将视图作业的一部分“委派”给另一个视图(另一条路线)

例如:

http://localhost:6543/sample_project/testruns/testrun001/report.html?action=edit
=> delegate to:
http://localhost:6543/sample_project/testruns/testrun001/report.json
我使用的视图包括:

# report:
@view_config(context=Root, route_name='report_route')
def report_view(context, request):
    ...
    if 'edit' in request.GET.getall('action'):
        # TODO: delegate to code_view
        ???
    ...
    # render report from report.json

# editor:
@view_config(context=Root, route_name='report_edit_route')
@view_config(context=Root, route_name='code_route')
def code_view(context, request):
    ....

您可以直接调用视图,它们根本不会经过金字塔路由器机制,该机制将
权限
和其他此类参数应用于视图。如果你想叫它,你可能已经知道这些了


实际上,您可能只想将公共功能重构为一个单独的功能,然后您的每个视图都可以将部分工作委托给该功能。

您可以直接调用视图,它们根本不会通过金字塔路由器机制,该机制将
权限
和其他此类参数应用于视图。如果你想叫它,你可能已经知道这些了


实际上,您可能只想将公共功能重构为一个单独的功能,然后您的每个视图都可以将部分工作委托给它。

我不知道Pyramid,但不只是
返回代码视图(上下文,请求)
工作?我不知道Pyramid,但不只是
返回代码视图(上下文,请求)
工作?谢谢Michael!我将遵循重构方法。这对我来说是个好建议。谢谢迈克尔!我将遵循重构方法。这对我来说是个好建议。