Y
Y
YuriyCherniy2020-05-08 21:07:08
Django
YuriyCherniy, 2020-05-08 21:07:08

How to correctly implement the navbar type setting?

It is necessary to implement the setting of the link type in the navbar, here are two screenshots for clarity:

spoiler

5eb5999ab973b235914419.png
5eb599a7ad4a1020834959.png

The left link can change its appearance at the request of the administrator, on the first screen it is 'Home', on the second 'Brand'. Now I store the link name in the database and display it to the user in the base template using a custom tag:
<a class="navbar-brand" href="{% url 'main_page_url' %}">{% get_brand %}</a>

I am concerned about the correctness of this approach, because every time you click on any link on the site, a request is made to the database to read the name of the button, which is probably not very good. Since I have 0 development experience, I cannot assess the adequacy of this approach, but I feel that this is not the best option. What are possible competent solutions to such a problem? Or for unloaded applications and is this a completely working option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PashaWNN, 2020-05-11
@YuriyCherniy

For inscriptions that rarely change (branding mentioned), I can offer this option: create a separate file, say, strings.py

SITE_NAME = 'Habr' # захардкожено
SITE_DESCRIPTION = os.getenv('SITE_DESCRIPTION')  # или можно взять из переменных окружения

And then just import the lines into the view and pass them to the template context

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question