I have a basic template when the user is logged in, and on this basic template I need to add user parameters in the drop-down menu. This drop-down menu with parameters should be constant for all handlers, i.e. Anytime a base template is invoked (extended) using a child template.
Besides executing the necessary database query, assigning the results of the query to a variable and passing this variable to each handler (there are many of them), how can I combine this into one query and one variable that is passed directly to the base template? I am using jinja2 templates.
I would really like to do something so bulky in exchange for something much simpler and more convenient.
Any ideas? Thanks.
EDIT
Therefore, I still have not found anything that I am looking for; However, I decided to at least make some progress in the interim. So, I created a custom decorator that returns a dict () view and adds the corresponding data to it. For instance:
def get_base_data(func): def wrapper(request): d = func(request) user_id = request.user.id
Now I can at least decorate each method very briefly and simply by setting:
@view_config(...) @get_base_data def my_handler(request): pass
Johnz source share