开发者

Where do I set common data for header in Pylons?

开发者 https://www.devze.com 2023-01-11 02:06 出处:网络
This is rather a general question about MVC. I have a set of templates for multiple controllers and their actions. All of them inherit from a overall template that contains footer/header.

This is rather a general question about MVC.

I have a set of templates for multiple controllers and their actions. All of them inherit from a overall template that contains footer/header.

I want header to render email of currently logged in user.开发者_运维知识库 Common task.

All tutorials are too simple to have basic example of how and where do I pass common data for all controller actions (set of actions).

Do I need to modify BaseController to add data to tmpl_context? Or create another class like BaseControllerForActionsWithHeaderData that has ____before____ method that sets tmpl_context.email... ?


If you need any of these variables, in principle, for each controller in your application, probably a good idea is to put them in the __before__ method of BaseController. If you need them only in few controllers you should probably create a separate class for it. Another option is to use decorators for each method...

Never in the documentation did not came across a suggestion how to do it in "pylons-style", but i don't think that is very important and you should choose the most convenient and "clean" way for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消