Rather than hard-code the configuration into a Python based settings file, when using a PaaS such as Heroku you want to pick up the MongoDB URI from the system settings. Here's what I do:
# get the dynamic elements from the MongoURI
import os
import re
r = r'^mongodb\:\/\/(?P ...There are comments.