Skip to main content

DjangoCMS HTML Meta tags for OpenGraph.

Project description

DjangoCMS Meta OG

HTML Meta tags OpenGraph for DjangoCMS. The project is based on the Django Meta OG project.

Install

pip install djangocms-meta-og

Add into settings.py:

from django.utils.translation import gettext_lazy as _
import sysconfig

INSTALLED_APPS = [
    "django_meta_og",
    "djangocms_meta_og",
    ...
]

TEMPLATES  = [
    {"OPTIONS": {
            "context_processors": [
                "djangocms_meta_og.context_processors.meta",
                ...
            ]
        }
    }
]

# Path to css and js used in admin form.
STATICFILES_DIRS = [
    os.path.join(sysconfig.get_paths()["purelib"], "djangocms_meta_og")
]

For js translations add into site urls.py:

from django.views.i18n import JavaScriptCatalog

urlpatterns = [
    ...
] + i18n_patterns(
    path('jsi18n/djangocms-meta-og/', JavaScriptCatalog.as_view(packages=['djangocms_meta_og']),
         name='jsi18n_djangocms_meta_og'),
    ...
)

Add into the templates:

{% load djangocms_meta_og %}
{% djangocms_meta_og_prefix as og_prefix %}
<head{% if og_prefix %} prefix="{{ og_prefix }}"{% endif %}>
    {% include "django_meta_og/header_meta.html" %}

The result can be:

<head prefix="og: https://ogp.me/ns#">
    <meta property="og:type" content="website" />
    <meta property="og:title" content="The Title" />
    <meta property="og:url" content="https%3A%2F%2Fexample.com%2F" />
    ...
</head>

Prefix for Meta tags in template

Some Meta tags may already be defined in the template. Their prefix is ​​included in the prefix list via the definition in settings:

# Example of tag definition already used in the templates.
META_OG_PREFIX_IN_TEMLATES = (
    ("og", "https://ogp.me/ns#"),
    ("article", "https://ogp.me/ns/article#"),
)

Dynamic content

Special values ​​can be replaced with some content. A list of these values ​​is provided in the form in the item administration.

# Dynamic content - Key replacement for specific content.
PAGE_META_OG_DYNAMIC_CONTENT = {
    "ogc:page_url": (
        "django_meta_og.dynamic_content.get_page_url",
        _("Set the page absolute URL (together with parameters)."),
    ),
    "ogc:current_page_url": (
        "djangocms_meta_og.dynamic_content.get_current_page_url",
        _("Set the page absolute URL."),
    ),
    "ogc:current_page_title": (
        "djangocms_meta_og.dynamic_content.get_current_page_title",
        _("Set the page title."),
    ),
    "ogc:current_page_description": (
        "djangocms_meta_og.dynamic_content.get_current_page_description",
        _("Set the page description."),
    ),
}

Edit form

In addition to administration, editing META values ​​is also available from the page menu.

Page Meta OG menu

Page Meta OG menu form

Admininstration

You can enter any Meta values. These are entered in four levels - Namespace, Property, Content and PageMetaOg. For this reason, a text form is set up for the META value, in which all these parts are combined in one edit in a text field.

Page Meta OG form

If you want to return to the default editing via select boxes, activate the switch in settings.py:

META_OG_USE_DEFAULT_PAGE_FORM = True

Page Meta OG default form

Namespace

Namespace list

Namespace form

Property

Property list

Property form

Content

Content list

Content form

Page Meta OG

Page Meta OG list

Page Meta OG form

License

BSD License

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

djangocms_meta_og-1.1.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djangocms_meta_og-1.1.0-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file djangocms_meta_og-1.1.0.tar.gz.

File metadata

  • Download URL: djangocms_meta_og-1.1.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for djangocms_meta_og-1.1.0.tar.gz
Algorithm Hash digest
SHA256 aebf2a0b9da62d632e00aaafbc72f044cd8920f581e71076617c15e4d5847655
MD5 7c5a634016deef61dcfd6727009554fa
BLAKE2b-256 9e5162bdcf322cdd1fafa51e71303b7ae68d49b3e0d6fd5614c8babf561d022b

See more details on using hashes here.

File details

Details for the file djangocms_meta_og-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for djangocms_meta_og-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da874c5522e16b8115eaf8f4152a415a5058ae4f473c3ba008689437e6c8498e
MD5 a475c63bc28b72fa8b983eac30adf5b7
BLAKE2b-256 ea893adfcd29699fda9d40bea23e746640a31bb0ff683e54c74db0f004834659

See more details on using hashes here.

Supported by

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