Package: django-json-ld
django-json-ldThis is a django template tag to help developers renderstructured datatags inside their django templates.Furthermore a collection of views and mixins are included:JsonLdContextMixin,JsonLdViewJsonLdSingleObjectMixin,JsonLdDetailViewInstallationInstall usingpip:pip install django-json-ldAdddjango_json_ldtoINSTALLED_APPSinsettings.py:INSTALLED_APPS = [
    # Other apps...
    'django_json_ld',
]SettingsYou can override the following options in settings.py:JSON_LD_CONTEXT_ATTRIBUTE: the context attribute name used indjango_json_ld's Class-Based Views (CBV). Defaults to'sd'.JSON_LD_MODEL_ATTRIBUTE: the model attribute name used byJsonLdDetailViewto get the model's structured data. Defaults to'sd'.JSON_LD_DEFAULT_CONTEXT: default json-ld context when usingdjango_json_ld's CBVs. Defaults to'https://schema.org/'.JSON_LD_INDENT: indent are used byjson.dumpsfunction to prettify output. Valid values areNoneor a non-negative integer. Defaults toNone- outputs on a single line. This setting is used only ifDEBUGisTrueJSON_LD_DEFAULT_TYPE: default json-ld type when usingdjango_json_ld's CBVs. Defaults to'Thing'.JSON_LD_GENERATE_URL: generate json-ld'surlfield when usingdjango_json_ld's CBVs. Defaults toTrue.JSON_LD_EMPTY_INPUT_RENDERING: behavior when the template tag receives an empty object. Possible values:strictdefault, raise TemplateSyntaxError.silentrenders nothing.generate_thingcreates object with URL of current page. eg:structured_data = {
                "@context": <JSON_LD_DEFAULT_CONTEXT>,
                "@type": <JSON_LD_DEFAULT_TYPE>,
                "url": <current_page_url>,
                }Usage ExampleAssuming you have a structured datasdlike the following in your context (copied from the link above).sd = {
  "@context": "https://schema.org/",
  "@type": "Organization",
  "url": "http://www.example.com/",
  "name": "Unlimited Ball Bearings Corp.",
  "contactPoint": {
    "@type": "ContactPoint",
    "telephone": "+1-401-555-1212",
    "contactType": "Customer service"
    }
}Then, in your template:{% load render_json_ld from json_ld %}
{% render_json_ld sd %}Would render into:<script type="application/ld+json">
{
  "@context": "https://schema.org/",
  "@type": "Organization",
  "url": "http://www.example.com/",
  "name": "Unlimited Ball Bearings Corp.",
  "contactPoint": {
    "@type": "ContactPoint",
    "telephone": "+1-401-555-1212",
    "contactType": "Customer service"
  }
}
</script>Class-Based View exampleSimple Viewviews.pyfromdjango_json_ld.viewsimportJsonLdContextMixinclassHomeView(JsonLdContextMixin,generic.ListView):structured_data={"@type":"Organization","name":"The Company","description":_("A great company."),}defget_structured_data(self):structured_data=super(HomeView,self).get_structured_data()structured_data["event"]=get_next_event()returnstructured_dataBy using{% render_json_ld sd %}, as explained in the previous example, would render into something like:{"@context":"https://schema.org/","@type":"Organization","name":"The Company","description":"Uma grande empresa.","url":"http://example.org/","event":{"@type":"Event","about":["Hodler","Monet","Munch"],"name":"Peindre l'impossible","startDate":"2016-09-15","endDate":"2017-01-22"}}In the above exampleJsonLdContextMixinaddssdtoHomeView's context.django_json_ldsupports lazy translations, hence"description"showing the translated version of its original value.Detail Viewviews.pyfromdjango_json_ld.viewsimportJsonLdDetailViewclassProductDetailView(JsonLdDetailView):model=Productmodels.pyclassProduct(models.Model):name=models.CharField(_('Name'),max_length=255)description=models.TextField(_('Description'))@propertydefsd(self):return{"@type":'Product',"description":self.description,"name":self.name,}By using{% render_json_ld sd %}, as explained previously, would render into something like:{"@context":"https://schema.org/","@type":"Product","name":"The Product","description":"A great product.","url":"http://example.org/products/1/the-product/"}In the above exampleJsonLdDetailViewaddssdtoProductDetailView's context, usingProduct's ownsdproperty. Theurlis generated automatically byJsonLdDetailView. This behaviour is configurable through settings.