The django application allows to add title, keywords and description meta tags to site's pages.
Project description
The django application allows to add title, keywords and description meta tags to site’s pages.
Features
Attaching meta tags to model instances
Attaching meta tags to URL paths
Caching
Integration with the django-modeltranslation application
Installation
pip install django-simple-metatags
Configuration
Add ‘metatags’ to your INSTALLED_APPS:
INSTALLED_APPS = (
# ...
'metatags',
)
Run the migrate management command:
python manage.py migrate metatags
Customize model admin classes:
To be able to attach meta tags to a model instance you should slightly adjust a model admin class.
The first way by adding the MetaTagInline class in inlines sequence:
from metatags.admin import MetaTagInline
class CustomModelAdmin(admin.ModelAdmin):
# ...
inlines = (MetaTagInline,)
The second way by using MetaTagAbleMixin:
from metatags.admin import MetaTagAbleMixin
class CustomModelAdmin(MetaTagAbleMixin, admin.ModelAdmin):
# ...
The third and way by using MetaTagAbleModelAdmin:
from metatags.admin import MetaTagAbleModelAdmin
class CustomModelAdmin(MetaTagAbleModelAdmin):
# ...
Load the metatags template library and add the include_metatags template tag in template.
Add the include_metatags template tag with the model_instance argument to use meta tags attached to a model instance.
{% load metatags %}
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
{% include_metatags object default_title='Foo' default_keywords='Foo, bar, baz' %}
</head>
Add the include_metatags without the model_instance argument to use meta tags attached to an URL path.
{% load metatags %}
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
{% include_metatags default_title='Foo' default_keywords='Foo, bar, baz' %}
</head>
Caching
Since version 2.0.0 application gained caching support. See settings section for more details.
Settings
METATAGS_CACHE_ENABLED - Enables meta tags caching to minimize database access. Defaults to False.
METATAGS_CACHE_ALIAS - A name of cache backend used by meta tags caching feature. Defaults to default.
METATAGS_CACHE_TIMEOUT - Timeout in seconds to use for meta tags caching. If value set up to None cached meta tags never expire. Defaults to None.
Management command
resetmetatagscache - Removes all cached meta tags.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.