简体   繁体   English

VPS 上的 Django SECRET_KEY

[英]Django SECRET_KEY on VPS

I'm working on a Djnago app that needs to be uploaded on a VPS.我正在开发一个需要在 VPS 上上传的 Djnago 应用程序。 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.我已经从 settings.py 中移动了我的 SECRET_KET 并将其放在我创建的 .env 文件中,并将 this.env 文件添加到 .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.当我将项目上传到我的 VPS 时,Django 无法找到我的 SECRET_KEY,因为在 VPS 的项目目录中显然找不到 .env 文件。

What should I do in this case and how am I supposed to call the SECRET_KEY on the server?在这种情况下我应该怎么做,我应该如何调用服务器上的 SECRET_KEY?

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.我立即想到的一个解决方案不是将您的项目上传到服务器,而是可以通过 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.我假设您正在使用 GitHub 来托管您的代码,在这种情况下,您可以创建一个只读部署密钥(请参阅https://docs.ZBF215181B5140522137B3D4F6B7B73544AZ-deploy-develop/密钥)并使用它来验证您的服务器与您的 GitHub 回购协议。

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.然后,您可以在服务器上的项目文件夹中创建一个.env文件,它不会被覆盖,因为它在您的 .gitignore 文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM