PYTHON   17

SEO objects

Guest on 30th April 2022 11:42:17 PM

  1. # -*- coding: utf-8 -*-
  2.  
  3. from django import template
  4. from ..models import SEO
  5.  
  6. register = template.Library()
  7.  
  8.  
  9. @register.inclusion_tag('seo/metatags.html', takes_context=True)
  10. def metatags(context):
  11.     path = context['request'].path
  12.     title = context.get('meta_title')
  13.     description = context.get('meta_description')
  14.     robots = None
  15.     url_canonica = None
  16.  
  17.     try:
  18.         seo_object = SEO.objects.get(url=path)
  19.         title = seo_object.meta_title
  20.         description = seo_object.meta_description
  21.         robots = seo_object.meta_robots
  22.         url_canonica = seo_object.url_canonica
  23.     except SEO.DoesNotExist:
  24.         pass
  25.  
  26.     return {
  27.         'title': title,
  28.         'description': description,
  29.         'robots': robots,
  30.         'url_canonica': url_canonica
  31.     }

Raw Paste


Login or Register to edit or fork this paste. It's free.