Skip to content
No description or website provided.
Python
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
getenv
tests
.gitignore
.travis.yml
AUTHORS.rst
CONTRIBUTING.rst
HISTORY.rst
LICENSE
MANIFEST.in
Makefile
README.rst
setup.cfg
setup.py
tox.ini

README.rst

django-getenv

https://badge.fury.io/py/django-getenv.png https://travis-ci.org/schwuk/django-getenv.png?branch=master Code Health https://pypip.in/d/django-getenv/badge.png

A quick'n'easy way to use environment variables in your Django (and Python) projects.

  • Free software: BSD license

Introduction

If you're using django-dotenv to get the most out of your .env file, you want to use the values there in your Django project's settings.

It will convert boolean, integer and float values to their native Python types.

There's nothing here that is Django specific, but I'm using it with Django so that's what I've called it.

Installation

pip install django-getenv

Usage

In your settings.py file (or equivalent), add:

from getenv import env

Then to read in your environment variables, do this:

SECRET_KEY = env("SECRET_KEY")

If you want to provide a default (in case the environment variable isn't set), try:

SECRET_KEY = env("SECRET_KEY", "a_secret_key")

You can also use getenv in a template:

:: {% load getenv %}

Current path: {% getenv "PATH" %}

For best results, mix with django-dotenv and dj-database-url.

Something went wrong with that request. Please try again.