R
R
rmfalx2017-07-13 13:45:07
Django
rmfalx, 2017-07-13 13:45:07

How to include meta tags in Django?

In general, I've already learned. I recently started learning python and along with it the django framework. Made a simple blog with one post model. How can I attach keywords, description and of course title meta tags to this model.
Found just such a thing
But I don’t understand what and where. Specifically, how to make it so that when creating a post at the end there are 3 more fields title, keywords, description and that they are displayed in the main template base.html

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rmfalx, 2017-07-13
@rmfalx

In short, I found some kind of shitty solution. It is implemented as a separate panel in the admin panel. There you insert the address of the page and meta tags to it, after which everything works. In short, some kind of crutch
What needs to be done

  1. $ pip install django-simple-metatags
  2. In the settings.py file in INSTALLED_APPS add 'metatags',
  3. Make table in DB $ python manage.py migrate metatags
  4. Add from metatags.admin import MetaTagInline to the admin.py file and write the class
    class CustomModelAdmin(admin.ModelAdmin):
    inlines = (MetaTagInline,)
  5. Insert {% load meta_tags %} into the body of the main template base.html at the very beginning and between the tag {% block meta_tags %}
    {% include_meta_tags %}
    {% endblock %}
    That's all. Looks terrible but worksf9b91b039ff84dfd9db71f0e1c1ddb9a.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question