Static text for dynamic text in Django templates

Greetings to all! I'm new to Django, but I've been digging for weeks. I am building a basic site around Django, and I am very excited that he himself and his capabilities. My question may sound "noob," and if so, please do not complain.

I developed a news feed, pages, comments, a taxonomy and a bunch of other things that are now ready for use, but when I came to the point where I had to apply the template to my website, I suddenly thought that I missed something - static text.

You know that all websites have some kind of static text everywhere, such as copyright notice, some slogan text, introductory text on the main page, some text and / or images in the sidebars that are static. I know that all of them can be broken down into models, but I don’t like the overhead of doing this for every small bit of text / raw html data on my site.

I thought about using a single model containing the name of the html block and its contents, and then selecting those that apply to a particular view and pass the contents to the template. So my question is the right thing? Will I store a copyright notice at the bottom of my site in a database? I could use one dictionary to store all the text blocks available for convenient use in my templates, but what if their number becomes very large? Should I request only those that I need in all my views? Or should I introduce a special template tag to do the job for me?

Just to give you an idea, here are two options that I mean:

# Option 1
{% load text %}
{% text some-text-label %}

# Option 2 (assuming text was passed in the Context)
{{ text.some-text-label %}

How exactly did you solve this problem?

? , , , , , . HTML, - ( ). , , ;)

!

+3
3

, :

  • base.html( someothername) .
  • (.. , ).
  • , .
  • .

, .

+1

I use django-flatblocks ( http://github.com/zerok/django-flatblocks ) to process such information and keep it manageable through the admin.

+1
source

Source: https://habr.com/ru/post/1772447/


All Articles