H
H
hobu4ok912017-05-12 13:36:37
Django
hobu4ok91, 2017-05-12 13:36:37

How to add a static template in django, such as a category menu, with the condition that these categories should be selected from the database?

If compared with the yii2 framework, then I need a widget that I once connected in the base template and which has its own controller to work with the base so that in each view in the views.py file I do not receive these categories

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artyom Innokentiev, 2017-05-12
@hobu4ok91

As far as I understand, you need to show the same element / block / some data on all pages of the site. There are 2 ways to do this:
1. Use context processors .
2. Write a mixin for the view (if it's a CBV) or a decorator (if it's an FBV) that will add the data you need to the context.
Both methods do the following - they add the data you need to the context, the data can be obtained from any source: random, API, database.

D
Dmitry Burnaev, 2017-05-12
@DmitryBurn

You can use the inclusion tag ... which renders the specified template with the right context ... I think it fits perfectly for the situation described ....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question