获取可通过其路径调用的金字塔视图(请求上下文) [英] Get Pyramid View callable by it's path (request context)

查看:27
本文介绍了获取可通过其路径调用的金字塔视图(请求上下文)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个应用程序,可以将 websocket 消息转换为对服务器的 AJAX 请求.这个决定主要是基于 Pyramid 已经有一个很好的 URL 调度系统,不使用它是愚蠢的.

I am making an app that would translate websocket messages to AJAX requests to the server. Mainly the decision is based on the fact that Pyramid already has a good URL dispatch system and it would be stupid not to use it.

问题是是否有一种简单的方法可以将 Pyramid 中的 URL(可能是实例化的 Request 对象)分派到它的视图可调用和获取视图可调用?或者至少获得与请求相关的可调用视图的输出?

The question is if there is an easy way to dispatch a URL in Pyramid (possibly an instanced Request object) to it's according view callable and get the view callable? Or at least get the output of the view callable related to the request?

我已经尝试过prequest.py"中的脚本,它基本上模拟了整个 HTTP 客户端并为您提供响应(我仍然没有设法让它工作,但无论如何查看源代码是有意义的),我会不喜欢那样做.

I have tried the script from "prequest.py" which basically emulates a whole HTTP client and gives you the response (I have still not managed to get it work, but a look through the sources makes sense anyway) and I wouldn't like to do it that way.

推荐答案

我已经在 Pyramid (1.4a1) 的最新版本中使用 Router.invoke_subrequest 设法做到了.

I have managed to do it using Router.invoke_subrequest in the latest version of Pyramid (1.4a1).

这将启用与路由相关的所有功能.URL 调度、参数传递、补间.

This enables all the features related to routing. URL dispatch, parameter passing, tweens.

您可以在这里阅读:http://docs.pylonsproject.org/projects/pyramid/en/latest/api/request.html#pyramid.request.Request.invoke_subrequest

这篇关于获取可通过其路径调用的金字塔视图(请求上下文)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆