Skip to main content

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-Agent matches a known bot/crawler (Googlebot, Bingbot, Twitterbot, GPTBot, ClaudeBot, etc.)
    — OR the URL contains _escaped_fragment_
    — OR the X-Bufferbot header 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prerender_django-1.0.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prerender_django-1.0.1-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

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

Hashes for prerender_django-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ca54c3864811bcb5d568aeddd085be6b9df038f471d23af3ac8ee742b4b9c348
MD5 21af3455a9469d28597e95f75b8f924e
BLAKE2b-256 24215116748f96aaf603f1c2d9d9e473c12da12d89a6a7743e71152f774c4f74

See more details on using hashes here.

File details

Details for the file prerender_django-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for prerender_django-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 34e037104695edaf3ef4b17d6f12f0a88f98cd9badeb3284f9205d9481f2e0e3
MD5 cf8721cafd0a18293a1fc37f00b10073
BLAKE2b-256 7cd4ee7f05d0e5abf2ab4b5f6fcb7729c1a27f8824ee0121cac63a1d51973a3e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page