From d61dd2ce4b48901e47c6f0f7cde231b92c3d5732 Mon Sep 17 00:00:00 2001 From: sosokker Date: Tue, 5 Sep 2023 21:44:19 +0700 Subject: [PATCH] Externalize DEBUG, TIMEZONE, ALLOW_HOST and Add Install instruction in README.md --- README.md | 2 ++ mysite/settings.py | 13 +++++++------ sample.env | 10 ++++++++++ 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 sample.env diff --git a/README.md b/README.md index 26841a6..fb28b26 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ or **Don't forget to change `your_secret_key` to your secret key (without quote)** +**You can look at `sample.env` for more information and others environment variables to set.** + 4. Run these commands ```bash python manage.py migrate diff --git a/mysite/settings.py b/mysite/settings.py index 7a27f5c..3906c9f 100644 --- a/mysite/settings.py +++ b/mysite/settings.py @@ -11,7 +11,7 @@ https://docs.djangoproject.com/en/4.2/ref/settings/ """ from pathlib import Path -from decouple import config +from decouple import config, Csv # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -20,14 +20,15 @@ BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = config('SECRET_KEY', default='fake-secret-key') +#! SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = config('SECRET_KEY', default='k2pd1p)zwe0qy0k25=sli+7+n^vd-0h*&6vga6oldq=781+7qw') -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +#! SECURITY WARNING: don't run with debug turned on in production! +DEBUG = config('DEBUG', default=False, cast=bool) -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='*', cast=Csv()) +TIME_ZONE = config('TIME_ZONE', default='Asia/Bangkok', cast=str) # Application definition diff --git a/sample.env b/sample.env new file mode 100644 index 0000000..c5af6b1 --- /dev/null +++ b/sample.env @@ -0,0 +1,10 @@ +# Copy this file to .env and edit the values +# Create a secret key using (todo: how to create a secret key?) +SECRET_KEY = secret-key-value-without-quotes +# Set DEBUG to True for development, False for actual use +DEBUG = False +# ALLOWED_HOSTS is a comma-separated list of hosts that can access the app. +# You can use wildcard chars (*) and IP addresses. Use * for any host. +ALLOWED_HOSTS = *.ku.th, localhost, 127.0.0.1, ::1 +# Your timezone +TIME_ZONE = Asia/Bangkok \ No newline at end of file