Background
⌘K

Django Integration

Learn how to integrate Affonso affiliate tracking into your Django application.

Silvestro
Written by Silvestro
Updated more than a month ago

Django Integration

Follow these steps to integrate Affonso tracking into your Django application using template inheritance and Django's settings system for clean configuration.

Add the tracking script to your base template at templates/base.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>{% block title %}Your Site{% endblock %}</title>

    <script
      async
      defer
      src="https://affonso.io/js/pixel.min.js"
      data-affonso="YOUR_PUBLIC_PROGRAM_ID"
      data-cookie_duration="30"
    ></script>
  </head>
  <body>
    {% block content %} {% endblock %}
  </body>
</html>

Method 2: Dynamic Configuration

For more flexibility, use Django settings:

Add to settings.py:

# settings.py
AFFONSO_PROGRAM_ID = 'your_program_id_here'
AFFONSO_COOKIE_DURATION = 30

Update your base template:

{% load static %}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>{% block title %}Your Site{% endblock %}</title>

    <script
      async
      defer
      src="https://affonso.io/js/pixel.min.js"
      data-affonso="{{ settings.AFFONSO_PROGRAM_ID }}"
      data-cookie_duration="{{ settings.AFFONSO_COOKIE_DURATION }}"
    ></script>
  </head>
  <body>
    {% block content %} {% endblock %}
  </body>
</html>

Find your Program ID →

Next Steps

Once installed, you can access affiliate referral data and pass it to your payment provider. Learn how to integrate with your payment provider →

Testing

  1. Start your Django server: python manage.py runserver
  2. Visit localhost:8000?atp=test
  3. Check browser DevTools → ApplicationCookiesaffonso_referral
  4. Deploy and verify tracking in your Affonso dashboard

Note: Make sure your ALLOWED_HOSTS includes your domain when deployed.

Was this article helpful?

If you still need help, our support team is here for you.

Contact Support
bg

Ready to Scale Your SaaS?

Affonso is the easiest way to launch your own affiliate program. We take care of the technical stuff, so you can focus on growing your business.