=================
kp_html_meta
kp_html_meta is a Django app to generate html meta tags for improve SEO.
Quick start
-
Install django-kp-html-meta::
pip install django-kp-html-meta
-
Add "kp_static_version" to your INSTALLED_APPS setting like this::
INSTALLED_APPS = [
...
'kp_html_meta',
]
-
Define default values in you settings.py (optional)::
Default values
KP_META = {
'kp_meta_title': "Test title", # ex: Test title
'kp_meta_description': "Test description", # ex:
'kp_meta_keywords': "Test keyword",
'kp_meta_graph_type': "article ",
'kp_meta_graph_image': "https://mywebsite.com/logo.jpg",
'kp_meta_graph_url': "https://mywebsite.com",
'kp_meta_graph_locale': "en",
'kp_get_base_url': "https://mywebsite.com",
'kp_meta_graph_site_name': "mywebsite",
}
-
Load templatetags into your template::
{% load kp_meta %}
{% kp_meta %}
-
Result::
Test title
Customization
The values defined in the settings.py file are default values.
They are used if no other values exist.
You can customize the content of the HTML tags according to your templates. Example::
from django.db import models
from kp_html_meta.models import KPMetaHelper
class DummyModel(models.Model, KPMetaHelper):
# ... some fields
def get_kp_meta_title(self):
# kp_meta_title in settings.py
return self.title
def get_kp_meta_description(self):
# kp_meta_description in settings.py
return self.text_of_my_article[:200]
def get_kp_meta_keywords(self):
# If None then the value defined in settings.py will be used.
# kp_meta_keywords in settings.py
return None
def get_kp_meta_graph_type(self):
return None
def get_kp_meta_graph_image(self):
return None
def get_kp_meta_graph_url(self):
return None
def get_kp_meta_graph_locale(self):
return None
def get_kp_meta_graph_site_name(self):
"""
Return site name
for example:
return "mywebsite.tld"
or
from django.conf import settings
kp_settings = getattr(settings, 'KP_META')
:return kp_settings['kp_meta_graph_site_name']
or
from django.contrib.sites.models import Site
current_site = Site.objects.get_current()
return current_site.domain
"""
return None
def get_kp_get_base_url(self):
"""
Return base url
for example:
return "https://mywebsite.tld"
or
from django.conf import settings
kp_settings = getattr(settings, 'KP_META')
:return kp_settings['kp_get_base_url']
or
from django.contrib.sites.models import Site
current_site = Site.objects.get_current()
return "https://%s" % current_site.domain
"""
return None
You can extend your templates with predefined fields::
from kp_html_meta.models import KPMetaGraphFiler
# if you use django-filer
class DummyModel(KPMetaGraphFiler):
from kp_html_meta.models import KPMetaGraphFileBrowser
# if you use django-filebrowser
class DummyModel(KPMetaGraphFileBrowser):
If you customize your models, use the templatetags like this::
{% load kp_meta %}
<head>
<meta charset="UTF-8">
{% kp_meta myobj %}
</head>