Skip to content

buraq.contrib.sites lets a single Buraq installation serve multiple domains, with per-domain configuration.

INSTALLED_APPS = ["buraq.contrib.sites", ...]
from buraq.contrib.sites.models import Site
await Site.objects.create(domain="example.com", name="Example")
await Site.objects.create(domain="staging.example.com", name="Staging")
from buraq.contrib.sites.models import Site
async def my_view(request):
site = await Site.get_current(request)
# Matches request Host header to site domain
# Falls back to first site if no match
return templates.TemplateResponse(request, "home.html", {"site": site})
<title>{{ site.name }}</title>
<meta property="og:url" content="https://{{ site.domain }}{{ request.url.path }}">

Per-site content:

class Article(Model):
site_id = Column(Integer, ForeignKey("sites_site.id"))
title = Column(String(255))
# Filter by current site
site = await Site.get_current(request)
articles = await Article.objects.filter(site_id=site.id).all()

Absolute URLs:

site = await Site.get_current(request)
absolute_url = f"https://{site.domain}/posts/{post.slug}"