All necessary keys will be added to the environ, but the values you pass in will take precedence. If you pass in base_url then wsgi.url_scheme, HTTP_HOST, and SCRIPT_NAME will be filled in from that value.
The pyramid.request.Request.invoke_subrequest() API accepts two
arguments: a positional argument request that must be provided, and
use_tweens keyword argument that is optional; it defaults to False.
It's a poor idea to use the original request object as an argument to
invoke_subrequest(). You should construct a new request instead as
demonstrated in the above example, using
pyramid.request.Request.blank(). Once you've constructed a request
object, you'll need to massage it to match the view callable you'd
like to be executed during the subrequest. This can be done by
adjusting the subrequest's URL, its headers, its request method, and
other attributes. The documentation for pyramid.request.Request
exposes the methods you should call and attributes you should set on
the request you create to massage it into something that will actually
match the view you'd like to call via a subrequest.
request_method This value can be a string (typically "GET", "POST",
"PUT", "DELETE", or "HEAD") representing an HTTP REQUEST_METHOD
我必须同意你的观点,文件有些模糊,但我想你可以这样使用它
^{pr2}$
摘要
你会想这样做的
subrequest = Request.blank('/relative/url')
# Configure the subrequest object
# set headers and other options you need.
request.invoke_subrequest(subrequest)
下面的代码对我有用。它复制所有(头、cookies、查询字符串、post参数等):
有点晚,但基于以上两个答案,我是如何做到这一点的。我不太喜欢above answer只复制所有内容。查看blank() method的文档,有一个
kw
参数,它说假设视图的请求包含子请求所需的正确标头信息和Cookie,则可以使用以下代码:
其他头信息(例如
accept
,accept_encoding
等)是pyramid.request对象的属性,可以像上面的代码片段一样添加到kwargs
字典中。在invoke_subrequest()
返回的对象是一个记录了here的响应对象。在我只是想知道你怎么传递标题和饼干?
来自http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/subrequest.html#subrequest-chapter:
这告诉我们构造函数只需要一个
Request
对象,以及可选的use_tweens
的值,所以不,这个不起作用。在
然后,从http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/subrequest.html
因此,基本上,您需要在将请求传递给
invoke_subrequest()
之前对其进行配置。在幸运的是有an entire page that documents the Request class。在那里我们可以找到很多配置它的选项,等等
不同方法的参数如何?文档只有一个POST关键字arg。
在Request class documentation页面上也有
在http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/viewconfig.html上我发现
我必须同意你的观点,文件有些模糊,但我想你可以这样使用它
^{pr2}$摘要
你会想这样做的
注意
我知道这不是一个100%完整的答案,有些代码,你可以复制粘贴,它将只是工作(特别是关于配置请求对象),但我认为这个答案包含一些信息,至少,会让你在正确的轨道上,我希望它会对你有所帮助。在
相关问题 更多 >
编程相关推荐