Home > database >  Django SECRET_KEY on VPS
Django SECRET_KEY on VPS

Time:11-24

I'm working on a Djnago app that needs to be uploaded on a VPS. I already have moved my SECRET_KET from settings.py and placed it inside .env file that I created and addedthis .env file to .gitignore.

When I'm uploading the project to my VPS, Django isn't able to locate my SECRET_KEY because obviously the .env file is not found inside my project directory on the VPS.

What should I do in this case and how am I supposed to call the SECRET_KEY on the server?

CodePudding user response:

A solution that immediately comes to my mind would be rather than upload your project to the server, you could pull it down onto the server via git.

I'm assuming you are using GitHub to host your code, in which case you can create a read only Deploy Key (see https://docs.github.com/en/developers/overview/managing-deploy-keys#deploy-keys) & use that to authenticate your server with your GitHub Repo.

You could then create a .env file in your project folder on the server & it won't be overwritten because it's in your .gitignore file.

  • Related