Skip to main content

Django Mailchimp v1.3

This is an integrated app for Django dealing with the Mailchimp mailing list system.

Quick start guide:

Installation:

  1. Install django-mailchimp-v1.3:

    pip install django-mailchimp-v1.3
  2. Add a MAILCHIMP_API_KEY to your settings.py with your mailchimp API key as the value (obviously)

  3. Add mailchimp to your project’s list of INSTALLED_APPS

4. To start using the API, you should start by using utils.get_connection(). This will use the API_KEY you just defined in settings.py

Subscribing a user to a list:

  1. To get the list:

    list = mailchimp.utils.get_connection().get_list_by_id(<list key id>)
  2. Now add a member to the mailing list:

    list.subscribe('example@example.com', {'EMAIL':'example@example.com'})

Those pesky merge vars:

General info:

Mailchimp is a quite generic service. As such, it needs to store information on people who subscribe to a list, and that information is specific to this very list!

So to help you build dynamic forms (presumabely), mailchimp added the merge_vars. They are, basically, a dictionnary showing infromation and meta-information defined for each piece of information. Here’s what the default set of merge vars look like (ona brand new list with default options):

[
    {
    'field_type': 'email',
    'name': 'Email Address',
    'show': True,
    'default': None,
    'req': True,
    'public': True,
    'tag': 'EMAIL',
    'helptext': None,
    'order': '1',
    'size': '25'
    },{
    'field_type': 'text',
    'name': 'First Name',
    'show': True,
    'default': '',
    'req': False,
    'public': True,
    'tag': 'FNAME',
    'helptext': '',
    'order': '2',
    'size': '25'
    },{
    'field_type': 'text',
    'name': 'Last Name',
    'show': True,
    'default': '',
    'req': False,
    'public': True,
    'tag': 'LNAME',
    'helptext': '',
    'order': '3',
    'size': '25'
    }
]

As you can see, it’s a list of 3 dictionnaries, each containing several fields that you should use to build your user interface with (since you’re using this app, that means your Django form).

Obtaining them:

You can recreate this list using the following API call:

list = mailchimp.utils.get_connection().get_list_by_id(<The list's key ID>)
print list.merges

Using them:

When you make a post to mailchimp, you need to pass merge_vars. For example, in a new list created with the default settings on the mailchimp website, the following call adds a member to a list (with a little more info than our bare minimum example up there):

list = mailchimp.utils.get_connection().get_list_by_id(<The list's key ID>)
list.subscribe('example@example.com', {'EMAIL': 'example@example.com', 'FNAME': 'Monthy', 'LNAME': 'Pythons'})

Note the use of the ‘tag’ field as the key for fields (why they didn’t call it ‘key’ or ‘id’ is beyond comprehension).

Create a view:

We’ll now try to move up the stack and create the necessary elements to make a useable mailchimp interface

Fire up your favorite editor and open your views.py. Put in the following snippet of code:

from django.http import HttpResponseRedirect
from mailchimp import utils

MAILCHIMP_LIST_ID = 'spamspamspamspameggsspamspam' # DRY :)
REDIRECT_URL_NAME = '/mailing_list_success/'
def add_email_to_mailing_list(request):
    if request.POST['email']:
        email_address = request.POST['email']
        list = utils.get_connection().get_list_by_id(MAILCHIMP_LIST_ID)
        list.subscribe(email_address, {'EMAIL': email_address})
        return HttpResponseRedirect('/mailing_list_success/')
    else:
        return HttpResponseRedirect('/mailing_list_failure/')

Of course, if you feel redirecting the user is not the right approach (handling a form might be a good idea), feel free to adapt this simple example to your needs :p

Metadata

Release files for django-mailchimp-v1.3 1.4.0

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-mailchimp-v1.3 1.4.0
File Size Uploaded Provenance
django-mailchimp-v1.3-1.4.0.tar.gz 31.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-mailchimp-v1.3 1.4.0
File Interpreter ABI Platform
django_mailchimp_v1.3-1.4.0-py2-none-any.whl Python 2 none any Details

Total release size: 81.4 kB

Release files / django-mailchimp-v1.3-1.4.0.tar.gz

Download URL django-mailchimp-v1.3-1.4.0.tar.gz
Size 31.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1e1fdfa35ddfbccf60607ec770194a71dcb122c66c79cff351bcba3016a60a08
BLAKE2b-256 checksum
How to use checksums
5831e5e3e4dfb38b28d03ed7176b1e676f52e8a7ccbd009cc3f476b1505591f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_mailchimp_v1.3-1.4.0-py2-none-any.whl

Download URL django_mailchimp_v1.3-1.4.0-py2-none-any.whl
Size 49.6 kB
Tags Python 2
SHA-256 checksum
How to use checksums
fe2fa04ab4368f45ba0bcf642f681cc3e409035d8e24fb02b287cb6cac3e1f7c
BLAKE2b-256 checksum
How to use checksums
853d8215c535d301524657f904d1fd4a799563aca8c68e54736b568e0d76c7ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-mailchimp-v1.3 1.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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