$ _SERVER vs. WSGI environ参数 [英] $_SERVER vs. WSGI environ parameter

查看:137
本文介绍了$ _SERVER vs. WSGI environ参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个网站。这是在一个很早的阶段,我必须做出决定是否使用服务器提供的SingleSignOn服务。 (这是一个校园网站,越来越多的网站在这里使用SSO,所以一般来说这是一个好主意)。
目标平台最有可能是通过mod_wsgi来django。但是,随该服务提供的任何文档都具有PHP代码。这种方法很大程度上依赖于使用自定义的 $ _ SERVER ['HTTPsomething'] 变量。不幸的是,现在我无法访问这种环境。



(如何)可以在django中访问这些自定义变量?根据 WSGI 文档,环境变量应包含尽可能多的变量。我可以确定我可以访问它们吗?

解决方案

在Django中,服务器环境变量是作为 META 属性在请求对象 - 所以在您看来,您可以随时通过请求访问它们.META ['foo'] 其中foo是变量的名称。



查看可用的简单方法是创建一个视图包含 assert False 来触发错误。只要您使用 DEBUG = True 运行,您将看到一个漂亮的错误页面,其中包含有关服务器状态的大量信息,包括所有请求属性。


I'm designing a site. It is in a very early stage, and I have to make a decision whether or not to use a SingleSignOn service provided by the server. (it's a campus site, and more and more sites are using SSO here, so generally it's a good idea). The target platform is most probably going to be django via mod_wsgi. However, any documentation provided with this service features php code. This method heavily relies on using custom $_SERVER['HTTPsomething'] variables. Unfortunately, right now I don't have access to this environment.

(How) can I access these custom variables in django? According the the WSGI documentation, the environ variable should contain as many as possible variables. Can I be sure that I can access them?

解决方案

In Django, the server environment variables are provided as dictionary members of the META attribute on the request object - so in your view, you can always access them via request.META['foo'] where foo is the name of the variable.

An easy way to see what is available is to create a view containing assert False to trigger an error. As long as you're running with DEBUG=True, you'll see a nice error page containing lots of information about the server status, including a full list of all the request attributes.

这篇关于$ _SERVER vs. WSGI environ参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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