A
A
Alexander Vinogradov2017-03-02 12:20:11
Django
Alexander Vinogradov, 2017-03-02 12:20:11

Basic template, dynamic menu. How to take it out separately?

As usual, we have a basic template. This template has blocks: block mainmenu and block content . The content block will change templates in the corresponding views.
My menu is dynamic and for the menu template you need to create your own variables.
In each view, I specify the base template, pass the name of the template for the content and all the necessary variables to form the menu.
But this is not the case that in each view it is necessary to form a list of variables for the menu.
Of course, you can take out the assignment of the name of the base template and the formation of the initial dictionary for the menu into an external function. But it seems to me that the return of the result will not look convenient here. It will be something like this:

def init():
    '''Формируем данные для базовой странице'''
    template_base = 'base.html'
    catalog_nodes = Catalogue.objects.all()
    contex_var = {'catalog_nodes': catalog_nodes}
    return template_base , contex_var

How to do it right?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question