DEV Community

Cover image for I Built a Django Package to Generate llms.txt Files Automatically
Kerim Yıldırım
Kerim Yıldırım

Posted on

I Built a Django Package to Generate llms.txt Files Automatically

If you're running a Django website, you probably want AI assistants like ChatGPT, Claude, and Perplexity to understand and reference your content accurately. That's exactly what https://llmstxt.org/ does — it's an open standard that tells LLMs
what your site is about.

I built django-llms-txt to automate this for Django projects.

The Problem

Manually maintaining an llms.txt file is tedious. Every time you add a blog post, a docs page, or a product page, you have to update the file. Forget once, and AI assistants miss your new content.

The Solution

pip install django-llms-txt

Add it to your settings and define your sections — either manually or by pointing it at your Django models:

# settings.py
INSTALLED_APPS = [
# ...
"django_llms_txt",
]

LLMS_TXT = {
"SITE_NAME": "My Django Project",
"SITE_URL": "https://example.com",
"DESCRIPTION": "A brief description of your website.",
"SECTIONS": [
{
"title": "Documentation",
"links": [
{
"name": "Getting Started",
"url": "/docs/start/",
"description": "Quick start guide",
},
],
},
],
}

Then include the URL patterns:

# urls.py
from django_llms_txt.urls import urlpatterns as llms_patterns

urlpatterns = [
# ...
] + llms_patterns

That's it. Your site now serves /llms.txt dynamically.

Auto-Generate from Models

The real power is auto-generating sections from your Django models. Have a blog? A product catalog? Documentation pages? Point the package at your models and it builds the llms.txt automatically:

LLMS_TXT = {
"SITE_NAME": "My Blog",
"SITE_URL": "https://example.com",
"DESCRIPTION": "A blog about Django.",
"AUTO_SECTIONS": [
{
"title": "Blog Posts",
"model": "blog.Post",
"filter": {"status": "published"},
"ordering": ["-published_date"],
"name_field": "title",
"url_method": "get_absolute_url",
"description_field": "excerpt",
"limit": 50,
},
],
}

Every time a new post is published, it shows up in your llms.txt — no manual updates needed.

Static File Generation

Prefer serving a static file instead of a dynamic view? Use the management command:

python manage.py generate_llms_txt --output static/

Output Format

The generated file follows the https://llmstxt.org/:

# My Django Project

A brief description of your website.

## Documentation

## Blog Posts

Links

Built by https://rapitek.com — we use this in production on our own site. Contributions and feedback welcome.

Top comments (0)