B
B
BoryanNikitin2020-01-17 05:14:20
Django
BoryanNikitin, 2020-01-17 05:14:20

How to upload a Django project to github with secret information in settings.py?

Hello!
There is a project written in Django. You need to upload it to github. Tell me what should be done with settings.py? After all, there is SECRET_KEY, information about connecting to the database. How to make it so that it's all hidden? And should it be hidden?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Web Dentist, 2020-01-17
@BoryanNikitin

https://github.com/joke2k/django-environ 1. Create an .env
file on your local machine in the settings folder. Write the following in it:

DEBUG=on
SECRET_KEY=blablasecret

2. Add the .env file to .gitignore 3.
In settings.py , replace your variables with these:
import environ
env = environ.Env(
    DEBUG=(bool, False)
)
environ.Env.read_env()
DEBUG = env('DEBUG')
SECRET_KEY = env('SECRET_KEY')

If you will deploy to a server (VPS) - add the same file and generate SECRET_KEY there

S
SexyHair, 2020-01-17
@SexyHair

I do this))
At the end of settings.py I add

try:
    from local_settings import *
except ImportError:
    pass

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question