{"id":5612,"library":"django-dotenv","title":"Django Dotenv","description":"django-dotenv is a Python library designed to simplify the loading of environment variables from .env files specifically within Django projects. It aims to make `manage.py` and WSGI applications aware of .env configurations, addressing a common configuration challenge for Django applications. As of its last release, it offers basic .env file parsing functionality.","status":"maintenance","version":"1.4.2","language":"en","source_language":"en","source_url":"https://github.com/jpadilla/django-dotenv","tags":["django","environment variables","dotenv","configuration","secrets"],"install":[{"cmd":"pip install django-dotenv","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The `load_dotenv` function is part of `python-dotenv`, which conflicts with `django-dotenv`.","wrong":"from dotenv import load_dotenv","symbol":"read_dotenv","correct":"import dotenv; dotenv.read_dotenv()"}],"quickstart":{"code":"import os\nimport dotenv\n\n# Recommended to call early in manage.py or wsgi.py\n# For manage.py, place before os.environ.setdefault(...)\n# For wsgi.py, place before application = get_wsgi_application()\ndotenv.read_dotenv()\n\n# Access environment variables as usual\nSECRET_KEY = os.environ.get('SECRET_KEY', 'your-fallback-secret-key')\nDEBUG = os.environ.get('DEBUG', 'False').lower() == 'true'\nDATABASE_URL = os.environ.get('DATABASE_URL', '')\n\nprint(f\"SECRET_KEY: {SECRET_KEY}\")\nprint(f\"DEBUG: {DEBUG}\")\nprint(f\"DATABASE_URL: {DATABASE_URL}\")","lang":"python","description":"To integrate django-dotenv, call `dotenv.read_dotenv()` early in your Django project's `manage.py` or `wsgi.py` file. This loads variables from a `.env` file (typically in the project root) into `os.environ`, making them accessible throughout your application."},"warnings":[{"fix":"Upgrade to a supported Python version (3.4+), or downgrade `django-dotenv` to a version older than 1.4.1.","message":"Support for Python 2.6 and Python 3.2 was removed in version 1.4.1. Projects still using these Python versions will need to either upgrade their Python environment or pin `django-dotenv` to an earlier version (e.g., `<1.4.1`).","severity":"breaking","affected_versions":">=1.4.1"},{"fix":"If using `django-dotenv`, ensure `python-dotenv` is *not* installed in the same environment. Uninstall `python-dotenv` to resolve the conflict (`pip uninstall python-dotenv`). If `python-dotenv` functionality is preferred, migrate to using `python-dotenv` instead, which is generally more actively maintained.","message":"A common `AttributeError: module 'dotenv' has no attribute 'read_dotenv'` occurs if `python-dotenv` is installed alongside `django-dotenv`. The `dotenv` module provided by `python-dotenv` can shadow the `django-dotenv`'s module, causing the `read_dotenv` function to be unavailable.","severity":"gotcha","affected_versions":"All"},{"fix":"To force the `.env` file's variables to override existing shell environment variables, call `dotenv.read_dotenv(override=True)`.","message":"By default, environment variables already defined in the shell take precedence over those specified in the `.env` file. This means shell variables will not be overridden by the `.env` file's contents unless explicitly instructed.","severity":"gotcha","affected_versions":"All"},{"fix":"Consider migrating to `python-dotenv` (`pip install python-dotenv`) and using `from dotenv import load_dotenv; load_dotenv()` instead, along with `os.getenv()` or similar mechanisms for accessing variables.","message":"The `django-dotenv` library has not been actively maintained since its last release (v1.4.2) in December 2017. For new projects or more robust and actively maintained `.env` handling, the `python-dotenv` library is generally recommended as a more universal solution, even for Django applications, due to its ongoing development and broader feature set.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}