12

I am trying to download a Django project from github and one of the requirements is:"As the project uses python-decouple you will need to create a file named .env on the root of the project with three values, as following:

DEBUG=True
SECRET_KEY='mys3cr3tk3y'
DATABASE_URL='postgres://u_bootcamp:p4ssw0rd@localhost:5432/bootcamp

"

1.What(where) is the root part of the project, is it part of the project where are settings?

2.What kind of file should .env be?(python package I suppose)

3.Should name of the file be simply .env(or something.env)?

4.Is .env file going to be imported in settings file?

shuttle87
  • 15,466
  • 11
  • 77
  • 106
Ismail Sarenkapic
  • 140
  • 1
  • 2
  • 9

1 Answers1

26
  1. What(where) is the root part of the project, is it part of the project where are settings?

    • Where your manage.py file is (that is your project root directory).
  2. What kind of file should .env be? (python package I suppose)

    • .env is a text file not a package.
  3. Should name of the file be simply .env (or something.env)?

    • Just .env
  4. Is .env file going to be imported in settings file?

    • No need to import, python-decouple automatically picks variables from there.

Read more about Where the settings data are stored? and Usage of python-decouple.

Aamir Rind
  • 38,793
  • 23
  • 126
  • 164
  • 3
    also, you need to mention that in .env the values should not be in quotes – Nikos Vita Topiko Apr 15 '17 at 09:38
  • Late response @NikosVitaTopiko, but does that include when the `SECRET_KEY` includes `#` character? For instance, if `SECRET_KEY=ABCD123#45`. The query here: https://stackoverflow.com/questions/17236850/setting-django-secret-key-in-environment-variable-fails-due-to-special-character suggests to add quotes. – Darcy Oct 25 '18 at 10:04
  • 1
    So how do you add .env to your server since it will be in .gitignore – Martins Jun 30 '19 at 00:35
  • 1
    @Martins Server should not be using `.env`, you should inject those environment variables directly (e.g. code deployment) – Aamir Rind Jul 01 '19 at 14:50
  • 1
    @Aamir Adnan I'm using python decouple adding my API keys to .bash_profile, will decouple config find the file? – Martins Jul 02 '19 at 02:53