所有模板中都可用的用户名
我正在尝试使当前登录的用户名在所有模板中可用。我可以从pyramid.security.authenticated_userid 接收它,但要做到这一点,我需要请求对象。我尝试通过 BeforeRender
订阅,但据我所知,请求未传递给该回调。
我还能如何使用户名随处可用(或实际上在基本模板中)?
I'm trying to make the currently logged in username available in all templates. I can receive it from pyramid.security.authenticated_userid
, but to do that I need the request object. I tried to go via the BeforeRender
subscription, but as far as I can tell, the request in not passed to that callback.
How else can I make the username available everywhere (or in the base template really)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种常见的方法是通过此 cookbook Recipe。
另一种可能性是按照您的建议使用
BeforeRender
订阅者附加它。请求
可从事件
获取:A common method is to attach the user object to the request via this cookbook recipe.
Another possibility is to attach it as you suggested using a
BeforeRender
subscriber. Therequest
is available from theevent
: