Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i have accidently delete my sceret key form settings.py in django

while pulling from git hub i lost my secret key which i have updated. is there any way to obtain secret key for the same project.

while pulling from git hub i lost my secret key which i have updated. is there any way to obtain secret key for the same project.

like image 564
learner Avatar asked Sep 27 '20 23:09

learner


People also ask

What happens if you change Django secret key?

Once you change the SECRET_KEY on production, all the old sessions and cookies are invalidated, users are logged out and data in sessions are lost. This is good if your SECRET_KEY is compromised!

What happens if Django secret key is exposed?

The secret key is used to encrypt communication in a Django project and as with any secret key used in cryptography, the secret key, if exposed, can and will be used to break any encryption in the project (mind you, even if you personally have not implemented encryption, Django uses that in many locations such as ...

What is secret key in Django settings py?

Summary: The Django secret key is used to provide cryptographic signing. This key is mostly used to sign session cookies. If one were to have this key, they would be able to modify the cookies sent by the application.


Video Answer


2 Answers

run : python manage.py shell write and enter the following lines sequentially:


from django.core.management.utils import get_random_secret_key
print(get_random_secret_key())
exit()

copy this secret_key to your settings.py SECRET_KEY. And reload this server. If it will not work, refresh the page with ctrl+shift+r, delete cache.

If it will not work again, try to remove all rows from django_session table where in your database.

My English skills are not good, sorry about that.

like image 180
Osman Durdag Avatar answered Oct 19 '22 00:10

Osman Durdag


I don't think there is a way to restore a secret key unless you remember a place where you stored it. But I don't think that's critical that you lost it, just set a new one. It should mostly affect the existing users' sessions, i.e. currently logged in users will be signed-out and will have to sign in again.

See what SECRET_KEY is used for here

Secret keys are not used for passwords of users and key rotation will not affect them.

like image 1
GProst Avatar answered Oct 19 '22 01:10

GProst