All Projects → jpadilla → Django Dotenv

jpadilla / Django Dotenv

Licence: mit
Loads environment variables from .env

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Dotenv

Django Unicorn
The magical reactive component framework for Django ✨
Stars: ✭ 431 (-10.4%)
Mutual labels:  django
Django Nested Admin
Django admin classes that allow for nested inlines
Stars: ✭ 463 (-3.74%)
Mutual labels:  django
Django Ordered Model
Get your Django models in order
Stars: ✭ 476 (-1.04%)
Mutual labels:  django
Drf Extra Fields
Extra Fields for Django Rest Framework
Stars: ✭ 445 (-7.48%)
Mutual labels:  django
Python Django Learning
🍺 python 和 diango 学习资料,书籍,文章,以及实战项目等等
Stars: ✭ 457 (-4.99%)
Mutual labels:  django
Yasql
基于Python开发的MySQL WEB版本的工单审核执行和SQL查询平台
Stars: ✭ 463 (-3.74%)
Mutual labels:  django
Django Test Plus
Useful additions to Django's default TestCase
Stars: ✭ 434 (-9.77%)
Mutual labels:  django
Django Redis Sessions
Session backend for Django that stores sessions in a Redis database
Stars: ✭ 478 (-0.62%)
Mutual labels:  django
Cookiecutter Django Vue
Cookiecutter Django Vue is a template for Django-Vue projects.
Stars: ✭ 462 (-3.95%)
Mutual labels:  django
Django Dbbackup
Management commands to help backup and restore your project database and media files
Stars: ✭ 471 (-2.08%)
Mutual labels:  django
Django Rest Framework
Web APIs for Django. 🎸
Stars: ✭ 22,406 (+4558.21%)
Mutual labels:  django
Django Machina
A Django forum engine for building powerful community driven websites.
Stars: ✭ 454 (-5.61%)
Mutual labels:  django
Django Role Permissions
A django app for role based permissions.
Stars: ✭ 465 (-3.33%)
Mutual labels:  django
Raveberry
A multi-user music server with a focus on participation
Stars: ✭ 442 (-8.11%)
Mutual labels:  django
Nestjs Config
Config module for nestjs using dotenv 🔑
Stars: ✭ 474 (-1.46%)
Mutual labels:  dotenv
Django Rest Framework Api Guide
Django REST framework API 指南
Stars: ✭ 437 (-9.15%)
Mutual labels:  django
Django Parler
Easily translate "cheese omelet" into "omelette au fromage".
Stars: ✭ 459 (-4.57%)
Mutual labels:  django
Mangum
AWS Lambda & API Gateway support for ASGI
Stars: ✭ 475 (-1.25%)
Mutual labels:  django
Django Dirtyfields
Tracking dirty fields on a Django model
Stars: ✭ 476 (-1.04%)
Mutual labels:  django
Knboard
Kanban boards with React & Django.
Stars: ✭ 470 (-2.29%)
Mutual labels:  django

django-dotenv

|build-status-image| |pypi-version|

foreman <https://github.com/ddollar/foreman>__ reads from .env. manage.py doesn't. Let's fix that.

Original implementation was written by @jacobian <https://github.com/jacobian>__.

Tested on Python 3.5, 3.6, 3.7 and 3.8.

Installation

::

pip install django-dotenv

Usage

Your manage.py should look like:

.. code:: python

#!/usr/bin/env python
import os
import sys

import dotenv


if __name__ == "__main__":
    dotenv.read_dotenv()

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)

You can also pass read_dotenv() an explicit path to the .env file, or to the directory where it lives. It's smart, it'll figure it out.

By default, variables that are already defined in the environment take precedence over those in your .env file. To change this, call read_dotenv(override=True).

Check out tests.py <https://github.com/jpadilla/django-dotenv/blob/master/tests.py>__ to see all the supported formats that your .env can have.

Using with WSGI


If you're running Django with WSGI and want to load a ``.env`` file,
your ``wsgi.py`` would look like this:

.. code:: python

    import os

    import dotenv
    from django.core.wsgi import get_wsgi_application

    dotenv.read_dotenv(os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env'))

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")

    application = get_wsgi_application()

That's it. Now go 12 factor the crap out of something.

Common problems
---------------

``AttributeError: module 'dotenv' has no attribute 'read_dotenv'``

There is another similar package, python-dotenv <https://github.com/theskumar/python-dotenv>__, which also contains a module called dotenv. If that package is installed, then you will see:

::

AttributeError: module 'dotenv' has no attribute 'read_dotenv'

To resolve this, uninstall python-dotenv.

read_dotenv is not reading from my environment file!


By default, variables that are already defined in the environment take
precedence over those in your ``.env`` file.  To change this, call
``read_dotenv(override=True)``.

.. |build-status-image| image:: https://travis-ci.org/jpadilla/django-dotenv.svg
   :target: https://travis-ci.org/jpadilla/django-dotenv
.. |pypi-version| image:: https://img.shields.io/pypi/v/django-dotenv.svg
   :target: https://pypi.python.org/pypi/django-dotenv
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].