How to do it...

  1. Add the following basic meta tag markup to meta.html:
{# templates/utils/meta.html #}
<meta name="{{ name }}" content="{{ content }}">
  1. Open the models.py file from this package in your favorite editor, and add the following content:
# utils/models.py
from django.db import models
from django.template import loader
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _

class MetaTagsMixin(models.Model):
"""
Abstract base class for generating meta tags
"""
class Meta:
abstract = True

meta_keywords = models.CharField(
_("Keywords"),
max_length=255,
blank=True,
help_text=_("Separate keywords by comma."))
meta_description = models.CharField(
_("Description"),
max_length=255,
blank=True)
meta_author = models.CharField(
_("Author"),
max_length=255,
blank=True)
meta_copyright = models.CharField(
_("Copyright"),
max_length=255,
blank=True)

def get_meta(self, name, content):
tag = ""
if name and content:
tag = loader.render_to_string('utils/meta.html', {
'name': name,
'content': content,
})
return mark_safe(tag)

def get_meta_keywords(self):
return self.get_meta('keywords', self.meta_keywords)

def get_meta_description(self):
return self.get_meta('description', self.meta_description)

def get_meta_author(self):
return self.get_meta('author', self.meta_author)

def get_meta_copyright(self):
return self.get_meta('copyright', self.meta_copyright)

def get_meta_tags(self):
return mark_safe(" ".join((
self.get_meta_keywords(),
self.get_meta_description(),
self.get_meta_author(),
self.get_meta_copyright(),
)))
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.23.127.197