Package: django-snakeoil
django-snakeoil helps manage your<meta>tags.Works on all supported Django versions using PostgreSQl, or with any database
on Django 3.1+.It offers full internationalization support (tags for multiple languages),
content set dynamically from object attributes, automatic Opengraph image
width and heights forImageField, and more.Full documentationGetting startedTo install,pip installdjango-snakeoilor use your favourite package
manager.You can use Snakeoil in two ways. If you’d like to attach metadata to an
object, you can use the model abstract base class:fromsnakeoil.modelsimportSEOModelclassArticle(SEOModel):title=models.CharField(max_length=200)author=models.ForeignKey(User,on_delete=models.CASCADE)main_image=models.Imagefield(blank=True,null=True)@propertydefauthor_name(self):return@propertydefsnakeoil_metadata(self):metadata={"default":[{"name":"author","content":self.author.get_full_name(),},{"property":"og:title","content":self.title},]}ifself.main_image:metadata.append({"property":"og:image","attribute":"main_image"})returnmetadataYou can also override these tags in the admin per-object.For situations where you can’t change the model (flatpages, third party apps)
or don’t have one at all, there is anSEOPathmodel that maps paths to
your meta tags.Tags are added in the admin (or however else you like) as JSON. For example:{"default":[{"name":"description","property":"og:description","content":"Meta description"},{"property":"og:title","content":"My blog post"},{"name":"author","attribute":"author_name"},{"property":"og:image","static":"img/default.jpg"}]}Wheredefaultwill work for any language. You can replacedefaultwith a language code, e.g. “nl_NL”, and these tags will only display if the
current language is Dutch. This will generate something like:<metaname="description"property="og:description"content="Meta description"><metaproperty="og:title""content="My blog post"><!-- from my_object.author_name --><metaname="author"content="Tom Carrick"><!-- build a static URL --><metaproperty="og:image"content="/static/img/default.jpg">Note that when usingstatic, width and height are not added, but you may
add these yourself. ForImageField, this will be added automatically:{"default":[{"property":"og:image","attribute":"main_image"}]}Results in:<metaproperty="og:image"content="/media/blog_1_main_image.jpg"><metaproperty="og:image:width"content="640"><metaproperty="og:image:height"content="480">Django TemplatesAddsnakeoilto yourINSTALLED_APPS:INSTALLED_APPS=["snakeoil",# ...]In your base template, add this where you want the tags to appear:{% load snakeoil %}
{% block head %}
    {% meta %}
{% endblock %}This will automatically find an object based on theget_absolute_url()of your model, by looking in the request context. If nothing is found,
snakeoil will check for anSEOPathobject for the current path. If
you have an object, it is recommended to pass it into the tag directly
to short-circuit the tag finding mechanisms:{% meta my_obj %}Jinja2Set your environment:fromjinja2importEnvironmentfromsnakeoil.jinja2importget_meta_tagsdefenvironment(**options):env=Environment(**options)env.globals.update({"get_meta_tags":get_meta_tags,# ...})returnenvIn your template:{% block meta %}
    {% with meta_tags=get_meta_tags() %}
        {% include "snakeoil/seo.jinja2" %}
    {% endwith %}
{% endblock meta %}To pass in an object:{% block meta %}
    {% with meta_tags=get_meta_tags(my_object) %}
        {% include "snakeoil/seo.jinja2" %}
    {% endwith %}
{% endblock meta %}NotesThanks to kezabelle for the name. For those wondering:Metadata is often used for SEO purposes. A lot of people (rightly or not)
consider SEO to be snakeoil. Also, SnakEOil. Very clever, I know.The old version of django-snakeoil can be found on theoldbranch, but
won’t be updated.