Skip to main content

Django BTCPay Donation

django-btcpay-donation is a Django application designed to help you easily track and manage generated links on a BTCPay Server for use via invoices. It allows you to centrally store links, group them by location, and switch between different configurations through the Django admin panel, automatically injecting active links into your template context.

Features:

  • URL Management: Save and automatically format BTCPay URLs by overriding the domain and Store ID via Django settings.
  • Location Grouping: Map specific donation links to physical locations on your site (e.g., "Sidebar", "Footer").
  • Flexible Configurations: Create sets of link locations and switch the "Active" set globally with a single click.
  • Automatic Context Injection: A custom middleware provides your templates with active donation links without manual view updates.

Installation

Install the package via pip:

pip install django-btcpay-donation

Requirements:

  • Python >= 3.10
  • Django >= 5.2

Configuration

  1. Update settings.py

    Add the app label to your INSTALLED_APPS list to enable app:

    INSTALLED_APPS = [
        ...,
        'django_btcpay_donation.apps.BtcpaydonationConfig',
        ...,
    ]
    

    Add the middleware to your MIDDLEWARE list to enable template context injection:

    MIDDLEWARE = [
        ...,
        'django_btcpay_donation.middleware.BTCPayDonationMiddleware', 
        ...,
    ]
    
  2. (Optional) Global BTCPay Settings

    You can define global parameters for your BTCPay Server. If these are set, the application will automatically replace the domain and Store ID in any saved links to match these values:

    # The domain of your BTCPay Server
    BTCPAY_DOMAIN = "https://btc-node.of.by"
    # Your specific Store ID
    BTCPAY_STORE_ID = "YourStoreID"
    
  3. Database Migrations

    Run migrations to create the necessary database tables:

    python manage.py makemigrations
    python manage.py migrate
    

Usage

  1. In Admin Interface

    Use the Django Admin to manage your setup:

    • BTCPay Donation Links: Add your raw BTCPay invoice URLs.
    • BTCPay Donation Link Locations: Assign links to specific named locations (e.g., top_banner).
    • BTCPay Donation Configurations: Create a named group of locations.
    • BTCPay Donation Current Configuration: Select which configuration is currently "Live" on the site.
    1. Templates

    The middleware automatically adds donation_link_locations to your template context. You can loop through them like this:

    {% if isBTCPayDonationMiddlewareConnected %}
        {% for location in donation_link_locations %}
            <a href="{{location.link}}">
                Donate
            </a>
        {% endfor %}
    {% endif %}
    

    Or select the spefic one:

    {% if isBTCPayDonationMiddlewareConnected %}
        {% for location in donation_link_locations %}
            {% if location.linklocation_name == "FOOTER" %}
                <a href="{{location.link}}">
                    Donate
                </a>
            {% endif %}
        {% endfor %}
    {% endif %}
    

    Where is the FOOTER is a name of a location assigned in admin while creating BTCPay Donation Link Locations.

URL Logic

When a BTCPayDonationLink is saved, the application parses the URL:

  • It replaces the host with BTCPAY_DOMAIN if configured.
  • It updates the storeId query parameter with BTCPAY_STORE_ID if configured.
  • This ensures that even if you migrate your BTCPay Server or change stores, you only need to update your settings.py.

License

This project is licensed under the MIT License. Author: Tim The Webmaster - timachuduk@gmail.com

Project Links

Release files for django-btcpay-donation 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-btcpay-donation 0.0.4
File Size Uploaded
django_btcpay_donation-0.0.4.tar.gz 17.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-btcpay-donation 0.0.4
File Interpreter ABI Platform
django_btcpay_donation-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 37.5 kB

Release files / django_btcpay_donation-0.0.4.tar.gz

Download URL django_btcpay_donation-0.0.4.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6d5655937919d566c61dfab5f3517a9e49f58bb80ea940f395a165a44b66f8d4
BLAKE2b-256 checksum
How to use checksums
d27fcac94d5dd720f8fa0f0a247cefdead148d1e8bae8c51347e2fc2719a4486
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Release files / django_btcpay_donation-0.0.4-py3-none-any.whl

Download URL django_btcpay_donation-0.0.4-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d5d52ae8dff9687614d8ebce6fca8587afcfb89cd05aa469b3ff2e50f1e56575
BLAKE2b-256 checksum
How to use checksums
9c7567826aee43cfb55d992accfd6d2c53611984f53c8df981406907189f7ee4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page