OG Images for Django
OG images for Django — template tag and you're done
Add dynamic Open Graph images to your Django templates. OGMagic's URL-based API means no Python packages to install — just a template tag.
Quick Start
Add OGMagic to your Django project — no packages to install, no API keys to configure.
{# templates/base.html #}
{% load urlencode from django.utils.http %}
<head>
{% with og_title=page_title|default:"My Site" %}
<meta property="og:image"
content="https://ogmagic.dev/api/og?template=gradient-mesh&title={{ og_title|urlencode }}&domain={{ request.get_host }}" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:card" content="summary_large_image" />
{% endwith %}
</head>Dynamic OG Images
Generate unique OG images per page using route data:
{# templates/blog/post_detail.html #}
{% block extra_head %}
<meta property="og:image"
content="https://ogmagic.dev/api/og?template=minimal-dark&title={{ post.title|urlencode }}&description={{ post.excerpt|truncatewords:20|urlencode }}&domain={{ request.get_host }}" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:card" content="summary_large_image" />
{% endblock %}
# Or create a template tag (templatetags/ogmagic.py)
from django import template
from urllib.parse import urlencode
register = template.Library()
@register.simple_tag(takes_context=True)
def ogmagic_url(context, title, template_name="gradient-mesh", **kwargs):
params = {"template": template_name, "title": title,
"domain": context["request"].get_host(), **kwargs}
return f"https://ogmagic.dev/api/og?{urlencode(params)}"💡 Works with Django templates, Jinja2, and Django REST Framework. Use urlencode filter or urllib.parse for clean URL construction.
Why use OGMagic with Django?
No build step
Images are generated on-demand via URL. No build plugins, no CI/CD changes.
55+ templates
Professional designs out of the box. Customize with query parameters.
No API key needed
Free tier works instantly — just use the URL. No signup, no config.
Every platform
Optimized 1200×630 images that look great on Twitter/X, Facebook, LinkedIn, Discord, and Slack.
Ready to add OG images to your Django app?
Start with 50 free API calls/month. No signup needed.