Django middleware for prerendering JavaScript-rendered pages for SEO via Prerender.io
Project description
prerender-django
Django middleware for Prerender.io. Intercepts requests from bots and crawlers and serves prerendered HTML, so your JavaScript-rendered app is fully indexable by search engines and social media scrapers.
Compatible with Django 5+ and Python 3.10+.
Installation
pip install prerender-django
Setup
Add the middleware to your settings.py:
MIDDLEWARE = [
'prerender_django.middleware.PrerenderMiddleware',
# ... your other middleware
]
PRERENDER_TOKEN = 'YOUR_PRERENDER_TOKEN'
The middleware must be placed before any session or authentication middleware to intercept bot requests early.
Settings
| Setting | Default | Description |
|---|---|---|
PRERENDER_TOKEN |
None |
Your Prerender.io token |
PRERENDER_SERVICE_URL |
https://service.prerender.io/ |
Prerender service URL (use this for self-hosted Prerender) |
Self-hosted Prerender
PRERENDER_SERVICE_URL = 'http://your-prerender-server:3000'
How it works
Requests are prerendered when all of the following are true:
- The HTTP method is
GET - The
User-Agentmatches a known bot/crawler (Googlebot, Bingbot, Twitterbot, GPTBot, ClaudeBot, etc.)
— OR the URL contains_escaped_fragment_
— OR theX-Bufferbotheader is present - The URL does not end with a static asset extension (
.js,.css,.png, etc.)
Everything else passes through to your normal Django views.
If the Prerender service is unreachable, the middleware falls back gracefully and serves the normal response.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prerender_django-1.0.1.tar.gz.
File metadata
- Download URL: prerender_django-1.0.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca54c3864811bcb5d568aeddd085be6b9df038f471d23af3ac8ee742b4b9c348
|
|
| MD5 |
21af3455a9469d28597e95f75b8f924e
|
|
| BLAKE2b-256 |
24215116748f96aaf603f1c2d9d9e473c12da12d89a6a7743e71152f774c4f74
|
File details
Details for the file prerender_django-1.0.1-py3-none-any.whl.
File metadata
- Download URL: prerender_django-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34e037104695edaf3ef4b17d6f12f0a88f98cd9badeb3284f9205d9481f2e0e3
|
|
| MD5 |
cf8721cafd0a18293a1fc37f00b10073
|
|
| BLAKE2b-256 |
7cd4ee7f05d0e5abf2ab4b5f6fcb7729c1a27f8824ee0121cac63a1d51973a3e
|