Skip to main content

Django integration for Web Monetization

Project description

Django Web Monetization

PyPI version Python Versions Django Versions License

A Django package that makes it easy to integrate the Web Monetization specification into web applications. It enables developers to monetize their websites through real-time payments using the Interledger Protocol (ILP).

Features

  • 🚀 Middleware to automatically add the payment pointer to HTTP headers
  • 🎯 Template tag to insert the monetization meta tag in templates
  • ⚙️ Simple configuration through settings.py
  • 🔒 Compatible with Django 3.2+
  • 📦 Easy installation with pip

Resources

Installation

pip install django-webmonetization

Configuration

  1. Add 'django_webmonetization' to INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
    ...
    'django_webmonetization',
]
  1. Configure your payment pointer in settings.py:
WEBMONETIZATION_PAYMENT_POINTER = '$ilp.example.com/your-payment-pointer'
  1. (Optional) Add the middleware to MIDDLEWARE in settings.py:
MIDDLEWARE = [
    ...
    'django_webmonetization.middleware.WebMonetizationMiddleware',
]

Usage

In Django Templates

{% load webmonetization %}
<!DOCTYPE html>
<html>
<head>
    {% webmonetization_meta %}
    <title>My Monetized Website</title>
</head>
<body>
    <h1>Welcome to my website</h1>
    <p>This site is monetized with Web Monetization</p>
</body>
</html>

HTTP Headers Verification

The middleware automatically adds the Web-Monetization-Pointer header to all HTTP responses. You can verify it with curl:

curl -I https://your-site.com

You should see something like:

HTTP/1.1 200 OK
...
Web-Monetization-Pointer: $ilp.example.com/your-payment-pointer

Integration Examples

1. Basic Monetization

# settings.py
WEBMONETIZATION_PAYMENT_POINTER = '$ilp.example.com/basic'

# views.py
from django.shortcuts import render

def home(request):
    return render(request, 'home.html')
<!-- templates/home.html -->
{% load webmonetization %}
<!DOCTYPE html>
<html>
<head>
    {% webmonetization_meta %}
</head>
<body>
    <h1>Home Page</h1>
</body>
</html>

Requirements

Main Dependencies

  • Python 3.7+
  • Django 3.2+

Development Dependencies

  • pytest>=7.0.0
  • pytest-cov>=4.0.0

Contributing

Contributions are welcome! Please feel free to submit a pull request.

License

MIT License - see the LICENSE file for details.

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

django_webmonetization_martinm10-0.1.2.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file django_webmonetization_martinm10-0.1.2.tar.gz.

File metadata

File hashes

Hashes for django_webmonetization_martinm10-0.1.2.tar.gz
Algorithm Hash digest
SHA256 40acfd61f2325998d2fae53f8a917931516b98788fa73f3fef67b4a29fb1e0f7
MD5 d3d20dd86db0b23abbdf88a0cf8011c7
BLAKE2b-256 e6890924e4ef6b0f0b1a41d611d9ca2f3d693fe941271ca7f632eb5238029c16

See more details on using hashes here.

File details

Details for the file django_webmonetization_martinm10-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_webmonetization_martinm10-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c127e90975267a3699ac6b42075f880477ac2ebf61d02fb57fcd6508356e88e9
MD5 d386cb85e282ec2a523bb6fd6d409189
BLAKE2b-256 b27b2fc1ae8e96e1e4d15508a45f2a69e22edce3a0c6cabb04761cf226afe0e5

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