gpt4 book ai didi

python - 从一种 View 委托(delegate)到另一种 View

转载 作者:太空宇宙 更新时间:2023-11-03 19:28:55 25 4
gpt4 key购买 nike

我使用 Pyramid 有不同的观点。我想知道是否可以将 View 作业的部分“委托(delegate)”给另一个 View (另一条路线)。

例如:

http://localhost:6543/sample_project/testruns/testrun001/report.html?action=edit
=> delegate to:
http://localhost:6543/sample_project/testruns/testrun001/report.json

我正在使用的 View :

# 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):
....

最佳答案

您可以直接调用 View ,它们根本不会通过将权限和其他此类参数应用于 View 的 Pyramid 路由器机制。不过,想必如果您尝试调用它,您已经知道这些事情了。

实际上,您可能只想将通用功能重构为单独的函数,然后每个 View 都可以将部分工作委托(delegate)给该函数。

关于python - 从一种 View 委托(delegate)到另一种 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6972674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com