Add automatic OG image generation to your Django views in minutes. No dependencies beyond standard Python.
Start IntegratingNo dependencies beyond standard Python. Uses urllib.parse for URL encoding.
Pass the OG image URL via context to your templates. Works with your existing views.
Use in base.html or individual templates. Just add meta tags with the og_url.
# views.py
import urllib.parse
from django.conf import settings
from django.shortcuts import render, get_object_or_404
def blog_post(request, slug):
post = get_object_or_404(Post, slug=slug)
og_url = "https://imagoapi.com/api/og/generate?" + urllib.parse.urlencode({
"title": post.title,
"template": "modern",
"api_key": settings.IMAGO_API_KEY,
})
return render(request, "blog/post.html", {"post": post, "og_url": og_url})
# In blog/post.html:
# <meta property="og:image" content="{{ og_url }}">
# <meta name="twitter:image" content="{{ og_url }}">
Start using Imago API today and add beautiful social cards to your Django app.
Try Imago API Free