每一个wsgi应用程序都更适合使用raptor。
raptorizemw的Python项目详细描述
安装
您可以使用pip自行安装:
$ pip install raptorizemw
或者您可以将raptorizemw添加到 setup.py项目的文件。
金字塔中的用法
编辑myapp/__init__.py并替换return config.make_wsgi_app() 行如下:
import raptorizemw app = config.make_wsgi_app() app = raptorizemw.make_middleware(app) return app
重新启动你的应用程序,但小心猛禽!
在烧瓶中使用
编辑yourapp.py并用以下内容替换app.run()行:
import raptorizemw app.wsgi_app = raptorizemw.make_middleware(app.wsgi_app) app.run()
僵尸!
在涡轮齿轮2中的使用
只需编辑myapp/config/middleware.py并将以下内容添加到 make_app(...):
# Wrap your base TurboGears 2 application with custom middleware here import raptorizemw app = raptorizemw.make_middleware(app)
在PasteDeploy管道中使用
您还可以将猛禽加入到PasteDeploy管道中,如下所示:
[pipeline:main] pipeline = raptorize my-app [filter:raptorize] use = egg:raptorizemw enterOn = konami-code delayTime = 3000 random_chance = 0.25 only_on_april_1st = True [app:myapp] ...
实际上,您可以在 WSGI管道,并根据Configuration相应地配置选项 下面一节。
配置
make_middleware(...)和RaptorizeMiddleware.__init__(...)都接受 许多配置关键字:
- ^{tt12}$ can be one of two actions: ‘timer’ or ‘konami-code’. If ‘timer’ is specified, then the raptor is shown on page load. If ‘konami-code’, then the raptor is shown if the page-viewing user enters the sacred sequence. Default is ‘timer’.
- ^{tt13}$ must be an ^{tt14}$ and is the number of milliseconds until the raptor is shown. Default is 2000.
- ^{tt15}$ must be a float between 0.0 and 1.0 representing a ‘percent chance’ to load the raptor. A value of 1.0 means the raptor will be injected every time; a value of 0.0 means it will never be injected; a value of 0.5 will result in a 50% chance of raptors. Default is 1.0.
- ^{tt16}$ should be a ^{tt17}$ value that will restrict raptors only to April Fool’s day. The configuration will coerce Boolean-like strings (such as ^{tt18}$, ^{tt19}$, ^{tt20}$, ^{tt21}$, ^{tt22}$ and ^{tt23}$) into a suitable format if provided in this manner (such as through a text-based pipeline configuration). Default is ^{tt24}$.
例如:
app = raptorizemw.make_middleware( app, enterOn='konami-code', delayTime=500, random_chance=0.5, only_on_april_1st=True )
将导致50%的网页加载猛禽在愚人节仅。这些 只有当用户同时输入konami代码时,才会显示raptors,并且 很快,只过了半秒钟。
学分
这个raptorize jquery插件的wsgi分类是编写的 通过Ralph Bean。真正的功劳归于 祖伯,他写了original jquery plugin。
获取源
代码和bug跟踪器位于http://github.com/ralphbean/raptorizemw。 请用叉子叉好