简体   繁体   English

如何在Python金字塔中使用拦截器?

[英]How to use interceptor in Python Pyramid?

I'm in need of a interceptor concept in pyramid for checking whether session is available or not on every view method call. 我需要金字塔中的拦截器概念来检查每个视图方法调用上的会话是否可用。 Is it possible to do that? 有可能这样做吗? I know that in Java Struts there is a concept called Login Interceptor which does the same. 我知道Java Struts中有一个称为Login Interceptor的概念,它的作用相同。 Is there any login interceptor concept in pyramid? 金字塔中是否有任何登录拦截器概念?

What Tom Willis suggests is one option, but I think what you really are looking for is event system: 汤姆·威利斯(Tom Willis)提出的建议是一种选择,但我认为您真正想要的是事件系统:

http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/narr/events.html http://docs.pylonsproject.org/projects/pyramid/zh-CN/1.5-branch/narr/events.html

You can subscribe to NewRequest to perform something based on the fact session/user us present or not. 您可以订阅NewRequest以根据我们存在或不存在的事实会话/用户来执行某些操作。

http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/api/events.html#pyramid.events.NewRequest http://docs.pylonsproject.org/projects/pyramid/zh-CN/1.5-branch/api/events.html#pyramid.events.NewRequest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM