Creating a model mixin to take care of meta tags

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.

Getting ready

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.

How to do it…

Put the following content in the models.py file:

# utils/models.py # -*- coding: UTF-8 -*- from __future__ import unicode_literals ...

Get Web Development with Django Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.