Search code examples
djangosecuritygithubpythonanywheresecret-key

Trying to hide django secret key, but getting error when deploying in PythonAnywhere


I'm trying to deploy a django project. I hid the secret key putting it in a file called .env and added it to .gitignore, so I have django's secret key only locally, and not in the git repository. But when I try to deploy the project in PythonAnywhere, an error occurs because there is no secret key in the repository (there is no file from where the server could read the secret key).

So I understand that it's not good to hard code the key, but how would I do to get a secret key for deployment?

I shouldn't have any secret key in the git repository, right?


Solution

  • I shouldn't have any secret key in the git repository, right?

    Right.

    So I understand that it's not good to hard code the key, but how would I do to get a secret key for deployment?

    The secret key can be stored as an environment variable or in a file that deploys alongside your project. Both options would have to be done through your host. Here's a Pythonanywhere suggestion for a file that deploys alongside your project: https://www.pythonanywhere.com/forums/topic/14207/