Skip to main content

The django application allows to add title, keywords and description meta tags to site's pages.

Project description

https://secure.travis-ci.org/whitespy/django-simple-metatags.svg https://badge.fury.io/py/django-simple-metatags.svg https://codecov.io/gh/whitespy/django-simple-metatags/branch/master/graph/badge.svg https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336

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

  1. Add ‘metatags’ to your INSTALLED_APPS:

INSTALLED_APPS = (
    # ...
    'metatags',
)
  1. Run the migrate management command:

python manage.py migrate metatags
  1. 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):
    # ...
  1. 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>

Arguments of include_metatags template tag

All arguments are optional.

model_instance - A model instance with attached meta tags. Defaults to None.

default_title - A default title of page. Defaults to ‘’.

default_keywords - Default keywords of page. Defaults to ‘’.

default_description - Default description of page. Defaults to ‘’.

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.

Source Distribution

django-simple-metatags-2.0.2.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

django_simple_metatags-2.0.2-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file django-simple-metatags-2.0.2.tar.gz.

File metadata

  • Download URL: django-simple-metatags-2.0.2.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for django-simple-metatags-2.0.2.tar.gz
Algorithm Hash digest
SHA256 745c41e83a33ad1e306f80d56493822731a44407b63ed7040c205d464f37ea5d
MD5 0f76ffa1f00c1e9ac2da6db1429e8de6
BLAKE2b-256 76b35fb173112958f3d0edc4408570cece891e2a71139b641ddd812f5039e05b

See more details on using hashes here.

File details

Details for the file django_simple_metatags-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: django_simple_metatags-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for django_simple_metatags-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 221e2f27b0e961f320b5254751437b6a752f0ec9ea7bdb4b38cae3c6a88079ce
MD5 66b2459efa3cd4d810b0e787e83fa84f
BLAKE2b-256 0f96f0c11c30df946c5863290383f10bbf5035753a987889d09c1aa0117d1d1c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page