Skip to content

Commit cedd319

Browse files
committed
Update README.md
1 parent fa2cf79 commit cedd319

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

README.md

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# django-dotenv
22

3-
[![Build Status](https://travis-ci.org/jpadilla/django-dotenv.svg)](https://travis-ci.org/jpadilla/django-dotenv)
4-
[![PyPI Version](https://pypip.in/version/django-dotenv/badge.svg)](https://pypi.python.org/pypi/django-dotenv)
3+
[![build-status-image]][travis]
4+
[![pypi-version]][pypi]
55

6-
[foreman](https://github.com/ddollar/foreman) reads from `.env`. `manage.py`
7-
doesn't. Let's fix that.
6+
[foreman][foreman] reads from `.env`. `manage.py` doesn't. Let's fix that.
87

9-
Tested on Python 2.6, 2.7, 3.2, 3.3, and 3.4.
8+
Original implementation was written by [@jacobian][jacobian].
9+
10+
Tested on Python 2.7, 3.3, 3.4, and 3.5.
1011

1112
## Installation
1213

@@ -16,31 +17,53 @@ pip install django-dotenv
1617

1718
## Usage
1819

19-
Pop open `manage.py`. Add:
20+
Your `manage.py` should look like:
21+
22+
```python
23+
#!/usr/bin/env python
24+
import os
25+
import sys
2026

21-
```
2227
import dotenv
23-
dotenv.read_dotenv()
24-
```
2528

26-
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.
2729

28-
### Production
30+
if __name__ == "__main__":
31+
dotenv.read_dotenv()
32+
33+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
2934

30-
In production environment, you might not need `manage.py` to run your application server. In that case, you need to put the code on `wsgi.py` like this:
35+
from django.core.management import execute_from_command_line
3136

37+
execute_from_command_line(sys.argv)
3238
```
39+
40+
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.
41+
42+
Check out [tests.py][tests-py] to see all the supported formats that your `.env` can have.
43+
44+
### Using with WSGI
45+
46+
If you're running Django with WSGI and want to load a `.env` file, your `wsgi.py` would look like this:
47+
48+
```python
3349
import os
3450

51+
import dotenv
3552
from django.core.wsgi import get_wsgi_application
3653

37-
import dotenv
3854
dotenv.read_dotenv(os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env'))
3955

40-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test.settings")
56+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
4157

4258
application = get_wsgi_application()
43-
4459
```
4560

4661
That's it. Now go 12 factor the crap out of something.
62+
63+
[build-status-image]: https://travis-ci.org/jpadilla/django-dotenv.svg
64+
[travis]: https://travis-ci.org/jpadilla/django-dotenv
65+
[pypi-version]: https://img.shields.io/pypi/v/django-dotenv.svg
66+
[pypi]: https://pypi.python.org/pypi/django-dotenv
67+
[foreman]: https://github.com/ddollar/foreman
68+
[jacobian]: https://github.com/jacobian
69+
[tests-py]: https://github.com/jpadilla/django-dotenv/blob/master/tests.py

0 commit comments

Comments
 (0)