Django RevProxy

0.13.0 · active · verified Fri Apr 17

Django RevProxy (version 0.13.0) is a Django application that provides a robust reverse proxy solution. It allows you to seamlessly proxy external websites or services through your Django application, handling URL rewriting, cookie management, and header forwarding. The library sees active, though irregular, development, with a focus on stability and compatibility with modern Django versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to add `django-revproxy` to your Django project. First, add 'revproxy' to your `INSTALLED_APPS`. Then, define a URL pattern in your `urls.py` that uses `RevProxy.as_view()` to point to an `upstream` URL. This example proxies all requests to `/external/` to `https://www.example.com/`. Remember to set a proper `SECRET_KEY` in production.

# myproject/settings.py
import os

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'revproxy',
]

SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'your-insecure-dev-secret-key')
DEBUG = True
ALLOWED_HOSTS = []

ROOT_URLCONF = 'myproject.urls'

# For simplicity in quickstart, typically more settings would be here

# myproject/urls.py
from django.contrib import admin
from django.urls import path, re_path
from revproxy.views import RevProxy

urlpatterns = [
    path('admin/', admin.site.urls),
    # Proxy all requests under /external/ to example.com
    # Access this at http://localhost:8000/external/
    re_path(r'^external/(?P<path>.*)$', RevProxy.as_view(upstream='https://www.example.com/'))
]

view raw JSON →