hiding secret key in django project on github after uploading project
Question:
I uploaded my django project on github and I have a lot of commits on my project.
I don’t want to delete my project and reupload it again.
what is the easiest way to hide secret key after uploading project to github and after a lot of commits?
Answers:
In the same directory where manage.py
is, create a file whose name is .env
, and put inside it:
SECRET_KEY = '....your secret key ....' # --- the one indicated in your settings.py, cut an paste it here
where SECRET_KEY = '....your secret key ....'
is the one indicated in your settings.py
.
So cut this line from your settings.py
and paste it in the .env
file.
In the same directory, create a file whose name is .gitignore
, and put inside it:
.env
Then in your settings.py
, where previously you had SECRET_KEY = '....your secret key ....'
, put:
from decouple import config
SECRET_KEY = config("SECRET_KEY") # this is to replace the secret key you cut away before
then in your command prompts run:
pip install python-decouple
pip freeze > requirements.txt
then add, commit and push on Github.
Here you can find out more information on how .gitignore works.
-
Create File => .env
-
Cut this from settings.py =>
SECRET_KEY = ‘—–your secret key—–‘
-
Paste in .env
-
Write this in settings.py =>
from decouple import config
SECRET_KEY = config("SECRET_KEY")
-
Write this in terminal or cmd =>
pip install python-decouple
-
Then write this in terminal or cmd =>
pip freeze > requirements.txt
-
Go in cPanel and upload File .env
Create a .env file in the root directory of your project. (Please refer to the snapshot below in case you have doubts)
Create a variable SECRET_KEY and enter its value by cut-pasting the value from SECRET_KEY in your project’s folder settings.py file
SECRET_KEY = '__VALUE_OF_SECRET_KEY__' #Value -> The value present in your settings.py
Navigate to the terminal and paste the below code:
pip install python-decouple
Import the below line to your settings.py
from decouple import config
Replace the value of SECRET_KEY with the below value:
SECRET_KEY = config("SECRET_KEY")
Please refer to the snapshot below to get a clear idea of the same:
I uploaded my django project on github and I have a lot of commits on my project.
I don’t want to delete my project and reupload it again.
what is the easiest way to hide secret key after uploading project to github and after a lot of commits?
In the same directory where manage.py
is, create a file whose name is .env
, and put inside it:
SECRET_KEY = '....your secret key ....' # --- the one indicated in your settings.py, cut an paste it here
where SECRET_KEY = '....your secret key ....'
is the one indicated in your settings.py
.
So cut this line from your settings.py
and paste it in the .env
file.
In the same directory, create a file whose name is .gitignore
, and put inside it:
.env
Then in your settings.py
, where previously you had SECRET_KEY = '....your secret key ....'
, put:
from decouple import config
SECRET_KEY = config("SECRET_KEY") # this is to replace the secret key you cut away before
then in your command prompts run:
pip install python-decouple
pip freeze > requirements.txt
then add, commit and push on Github.
Here you can find out more information on how .gitignore works.
-
Create File => .env
-
Cut this from settings.py =>
SECRET_KEY = ‘—–your secret key—–‘
-
Paste in .env
-
Write this in settings.py =>
from decouple import config
SECRET_KEY = config("SECRET_KEY")
-
Write this in terminal or cmd =>
pip install python-decouple
-
Then write this in terminal or cmd =>
pip freeze > requirements.txt
-
Go in cPanel and upload File .env
Create a .env file in the root directory of your project. (Please refer to the snapshot below in case you have doubts)
Create a variable SECRET_KEY and enter its value by cut-pasting the value from SECRET_KEY in your project’s folder settings.py file
SECRET_KEY = '__VALUE_OF_SECRET_KEY__' #Value -> The value present in your settings.py
Navigate to the terminal and paste the below code:
pip install python-decouple
Import the below line to your settings.py
from decouple import config
Replace the value of SECRET_KEY with the below value:
SECRET_KEY = config("SECRET_KEY")
Please refer to the snapshot below to get a clear idea of the same: