Django Quickstart
License-protect your Django application with middleware and decorators.
5 minute setup
$
pip install traffic-orchestrator-django
1
Install the SDK
Install the Traffic Orchestrator Django package from PyPI.
bash
pip install traffic-orchestrator-django
2
Configure Django Settings
Add Traffic Orchestrator to your Django settings with your API endpoint.
python
# settings.py
INSTALLED_APPS = [
...
'traffic_orchestrator',
]
TRAFFIC_ORCHESTRATOR = {
'BASE_URL': 'https://api.trafficorchestrator.com/api/v1',
'CACHE_TTL': 3600, # Cache validation results (optional)
}
3
Validate with a Decorator
Protect views with the license_required decorator.
python
from traffic_orchestrator.decorators import license_required
@license_required(feature="pro")
def premium_dashboard(request):
# Only accessible with a valid license
# that includes the "pro" feature
return render(request, "dashboard/pro.html")
# Or validate manually in any view
from traffic_orchestrator import get_client
def my_view(request):
client = get_client()
result = client.validate(
key=request.user.license_key,
domain=request.get_host()
)
if result["valid"]:
return render(request, "premium.html")
return redirect("upgrade")
4
Middleware Integration
Add license checking as Django middleware for site-wide enforcement.
python
# settings.py
MIDDLEWARE = [
...
'traffic_orchestrator.middleware.LicenseMiddleware',
]
# The middleware will:
# 1. Check the license on every request
# 2. Set request.license with the validation result
# 3. Cache results per Django's cache framework
# Then in any view:
def my_view(request):
if request.license.valid:
# Licensed user
features = request.license.features
else:
# Unlicensed — show upgrade prompt
pass