File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,6 +49,9 @@ Add the following code to your ``settings.py``
4949 dotenv_path = join(dirname(__file__ ), ' .env' )
5050 load_dotenv(dotenv_path)
5151
52+ # OR, the same with increased verbosity:
53+ load_dotenv(dotenv_path, verbose = True )
54+
5255 Alternatively, you can use ``find_dotenv() `` method that will try to find a
5356``.env `` file by (a) guessing where to start using ``__file__ `` or the working
5457directory -- allowing this to work in non-file contexts such as IPython notebooks
Original file line number Diff line number Diff line change @@ -16,12 +16,13 @@ def decode_escaped(escaped):
1616 return __escape_decoder (escaped )[0 ]
1717
1818
19- def load_dotenv (dotenv_path ):
19+ def load_dotenv (dotenv_path , verbose = False ):
2020 """
2121 Read a .env file and load into os.environ.
2222 """
2323 if not os .path .exists (dotenv_path ):
24- warnings .warn ("Not loading %s - it doesn't exist." % dotenv_path )
24+ if verbose :
25+ warnings .warn ("Not loading %s - it doesn't exist." % dotenv_path )
2526 return None
2627 for k , v in dotenv_values (dotenv_path ).items ():
2728 os .environ .setdefault (k , v )
Original file line number Diff line number Diff line change 1010
1111def test_warns_if_file_does_not_exist ():
1212 with warnings .catch_warnings (record = True ) as w :
13- load_dotenv ('.does_not_exist' )
13+ load_dotenv ('.does_not_exist' , verbose = True )
1414
1515 assert len (w ) == 1
1616 assert w [0 ].category is UserWarning
You can’t perform that action at this time.
0 commit comments