Skip to main content

A simple Django module for adding structured data and OpenGraph tags to your views.

Project description

Django Structured Data PyPI

Template tags to assist in adding structured metadata to views and models.

Install

  1. Add "structured_data" to your INSTALLED_APPS:
INSTALLED_APPS = [
    ...
    'structured_data',
]

Use

In models

Define a structured_data property on your models. This is written in a standard JSON-LD format. Included below is a complicated example.

    @property
    def structured_data(self):
        url = SITE_URL + self.get_absolute_url()
        data = {
            '@type': 'BlogPosting',
            'headline': self.title,
            'author': {
                '@type': 'Person',
                'name': self.author
            },
            'datePublished': self.created,
            'dateModified': self.modified,
            'url': url,
            'mainEntityOfPage': {
                '@type': 'WebPage',
                '@id': url
            },
        }
        if self.image:
            data['image'] = SITE_URL + self.image.url

        return data

In templates

Use the json_ld_for template tag to render your structured data as JSON-LD.

{% load jsonld %}
{% json_ld_for post %}

A second template tag, og_for, is also included. This attempts to translate your JSON-LD data to Open Graph tags that can be read by Facebook, Twitter, Telegram and more.

{% load opengraph %}
{% og_for post %}

A third template tag, meta_for, will render the description field from your JSON-LD data as a standard HTML meta description tag.

{% load meta %}
{% meta_for post %}

License

This software is released under the MIT license.

Copyright (c) 2019-2026 Luke Rogers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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_structured_data-0.8.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

django_structured_data-0.8.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file django_structured_data-0.8.0.tar.gz.

File metadata

  • Download URL: django_structured_data-0.8.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for django_structured_data-0.8.0.tar.gz
Algorithm Hash digest
SHA256 b60a82df17b19d283d7df170da7cb7f82a3cfc6659811457ed01042e3181837b
MD5 8326f967245735d78f5f38b13ba8651c
BLAKE2b-256 d75c2fbc4a1e4c21d54543a6837340e025a48aec98f9837fad760cd240c0391d

See more details on using hashes here.

File details

Details for the file django_structured_data-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: django_structured_data-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for django_structured_data-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be23a1f9339e2a611666fa07dec60f196ecfebc66a6beb09441e8ef600047aa7
MD5 0843f8127c68584eb5b2c2bb697e85cf
BLAKE2b-256 cc48ed8237fb496735213612f2fd7c63d7136347c55c9ea5cca5f4da80e219e6

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