[Answered ]-Django Local Environment Settings

2👍

First, in your project folder create a virtualenv:

python -m venv .venv

Activate your virtualenv:

source .venv/bin/activate

Install Django with your virtualenv activated:

pip install django

Then install python-decouple:

pip install python-decouple

It helps you to extract your local settings.

  1. Create a .env file in your project root
  2. Extract all your settings from settings.py, example:

.env

SECRET_KEY=CHANGE_THIS_FOR_YOUR_SECRET_KEY
DEBUG=True

settings.py

from decouple import config

SECRET_KEY = config('SECRET_KEY')
DEBUG = config('DEBUG', default=False, cast=bool)

For last, but not less important, add the .env file in your .gitignore, so any developer who gets your code won’t use your local settings.

0👍

Started a new project. And you replaced the settings.py from another project? If so just update your database and install the required packages with pip. To update the database: python manage.py makemigrations and then python manage.py migrate.

Leave a comment