0

I have deployed a Flask web app to a Digital Ocean droplet running Ubuntu 18.04. The web app is simply a landing page that has a single form that adds a visitor's email address to a Mailchimp mailing list.

The web app works perfectly in development, however the form submission does not work in production. Submitting the form just reloads the page. It does not submit the email address to the mailing list nor is the 'thank you' page displayed.

In development, I am using the default Flask WSGI server to directly access the web app (i.e. localhost:5000).

In production, I am using Nginx in conjunction with Gunicorn. As a sanity test, I ran the app using Flask's default WSGI server in production and it worked fine.

Aside from using Nginx and Gunicorn, the web app code and configuration (e.g. Mailchimp list id / api key) are identical across both environments.

What could be causing this problem?

Josh
  • 111
  • 1

1 Answers1

1

The problem was due to the Mailchimp API key not being read in from my .flaskenv file.

In development, it appears that the .flaskenv file is implicitly loaded by python-dotenv but in production you need to explicitly load the file.

import os
from dotenv import load_dotenv


# explicitly load .flaskenv
basedir = os.path.abspath(os.path.dirname('__file__'))
load_dotenv(os.path.join(basedir, '.flaskenv'))


class Config(object):
    SECRET_KEY = os.environ.get('SECRET_KEY')
    MAILCHIMP_API_KEY = os.environ.get('MAILCHIMP_API_KEY')
    MAILCHIMP_LIST_ID = os.environ.get('MAILCHIMP_LIST_ID')

Josh
  • 111
  • 1