Autogenerate secret key

This commit is contained in:
Tomasz 2021-01-28 20:48:04 +01:00
parent 220ecbf243
commit bc8ad0dee2
4 changed files with 3 additions and 14 deletions

View file

@ -1 +0,0 @@
SECRET_KEY = VULCANWEBKEY

View file

@ -25,12 +25,7 @@ And in frontend:
```shell ```shell
npm install npm install
``` ```
## 2. Create .env and make migrations ## 2. Make migrations
In the .env file put the code:
```shell
SECRET_KEY = VULCANWEBKEY
```
After saving the files, we migrate with these commands:
```shell ```shell
python manage.py makemigrations python manage.py makemigrations
python manage.py migrate python manage.py migrate

View file

@ -1,6 +1,5 @@
beautifulsoup4==4.9.3 beautifulsoup4==4.9.3
bs4==0.0.1 bs4==0.0.1
Django==3.1.3 Django==3.1.3
python-dotenv==0.15.0
requests==2.24.0 requests==2.24.0
cryptography==3.2.1 cryptography==3.2.1

View file

@ -12,7 +12,7 @@ https://docs.djangoproject.com/en/3.1/ref/settings/
from pathlib import Path from pathlib import Path
import os import os
import dotenv from cryptography.fernet import Fernet
ROOT_PATH = os.path.dirname(__file__) ROOT_PATH = os.path.dirname(__file__)
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
@ -22,11 +22,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
dotenv_file = os.path.join(BASE_DIR, ".env") SECRET_KEY = Fernet.generate_key().decode('utf-8')
if os.path.isfile(dotenv_file):
dotenv.load_dotenv(dotenv_file)
SECRET_KEY = os.environ['SECRET_KEY'] # Instead of your actual secret key
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True