[Django]-Using environment variables for mysql database password and host throws errors

3πŸ‘

βœ…

I figured out the issue.

For anyone running into this problem on PythonAnywhere, there are two different wsgi.py files. The first one is found in the same directory as settings.py (which was the one I was working with), while the other is under the β€œWeb” tab and linked under the β€œCode:” section. The latter is the one that needed to be edited. Adding the following to that wsgi.py file (above the application = get_wsgi_application() line) got all my environment variables working properly:

from dotenv import load_dotenv

project_folder = os.path.expanduser('~/<insert-your-project-directory-here>')
load_dotenv(os.path.join(project_folder, '.env'))
πŸ‘€Megan

Leave a comment