If you want to optimize your site for search engines, you need to not only set the semantic markup for each page but also the appropriate meta tags. For maximum flexibility, you need to have a way to define specific meta tags for each object, which has its own page on your website. In this recipe, we will see how to create a model mixin for the fields and methods related to the meta tags.
As seen in the previous recipes, make sure that you have the utils
package for your mixins. Open the models.py
file from this package in your favorite editor.
Put the following content in the models.py
file:
# utils/models.py # -*- coding: UTF-8 -*- from __future__ import unicode_literals from django.db import models from django.utils.translation import ugettext_lazy as _ from django.template.defaultfilters import escape from django.utils.safestring import mark_safe class MetaTagsMixin(models.Model): """ Abstract base class for...