From 090cd7574bb4071088e08f82b3f6578a0feb3684 Mon Sep 17 00:00:00 2001 From: martcpp Date: Tue, 12 Mar 2024 12:40:57 +0100 Subject: [PATCH 1/4] added a script tto generate serect key --- .env.example | 3 +-- README.md | 12 ++++++++++-- hello_world/settings.py | 5 +++-- secretgen.py | 7 +++++++ 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 secretgen.py diff --git a/.env.example b/.env.example index a316a01..c78ddce 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,7 @@ SECRET_KEY=my_secret_key DEBUG=True -# ALLOWED_HOSTS=yourdomain.com,anotherdomain.com (Each host is separated by a comma) -ALLOWED_HOSTS=* +# Database DB_HOST=127.0.0.1 DB_PORT=3306 diff --git a/README.md b/README.md index 2d3d97e..6d9dcad 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,20 @@ Welcome to your shiny new Codespace running Django! We've got everything fired u You've got a blank canvas to work on from a git perspective as well. There's a single initial commit with the what you're seeing right now - where you go from here is up to you! Everything you do here is contained within this one codespace. There is no repository on GitHub yet. If and when you’re ready you can click "Publish Branch" and we’ll create your repository and push up your project. If you were just exploring then and have no further need for this code then you can simply delete your codespace and it's gone forever. -To collect static files: +### to generate secretkey for djanggo project run + +```python +python secretgen.py +``` + + + +### To collect static files: ```python python manage.py collectstatic ``` -To run this application: +### To run this application: ```python python manage.py runserver diff --git a/hello_world/settings.py b/hello_world/settings.py index 0d8efd3..bac813a 100644 --- a/hello_world/settings.py +++ b/hello_world/settings.py @@ -14,6 +14,7 @@ from pathlib import Path from dotenv import load_dotenv + load_dotenv() # Build paths inside the project like this: BASE_DIR / 'subdir'. @@ -24,12 +25,12 @@ # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = os.getenv("SECRET_KEY") +SECRET_KEY = "g^z39h3@0h^+)ch1pin+gv1y9^%w_n88ss6lnx!9#^_h8d8&7g" # SECURITY WARNING: don't run with debug turned on in production! DEBUG = os.getenv("DEBUG") -ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '').split(',') +ALLOWED_HOSTS = ["*"] if 'CODESPACE_NAME' in os.environ: codespace_name = os.getenv("CODESPACE_NAME") diff --git a/secretgen.py b/secretgen.py new file mode 100644 index 0000000..e7c8bea --- /dev/null +++ b/secretgen.py @@ -0,0 +1,7 @@ +from django.core.management.utils import get_random_secret_key + +# Generate a random secret key +secret_key = get_random_secret_key() +print("please copy this code and replace it in your .env file secret key") +print(secret_key) + From 1eda32f167df57c763d0ef29b709ca1087bc52e7 Mon Sep 17 00:00:00 2001 From: martcpp Date: Tue, 12 Mar 2024 12:43:28 +0100 Subject: [PATCH 2/4] added a script tto generate serect key --- hello_world/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hello_world/settings.py b/hello_world/settings.py index bac813a..92cebe5 100644 --- a/hello_world/settings.py +++ b/hello_world/settings.py @@ -25,7 +25,7 @@ # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "g^z39h3@0h^+)ch1pin+gv1y9^%w_n88ss6lnx!9#^_h8d8&7g" +SECRET_KEY = os.getenv('my_secret_key') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = os.getenv("DEBUG") From c9321c46b81c0ec1088cc762206110928ce922f3 Mon Sep 17 00:00:00 2001 From: martcpp Date: Tue, 12 Mar 2024 12:47:15 +0100 Subject: [PATCH 3/4] added a script tto generate serect key --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d9dcad..7434758 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ You've got a blank canvas to work on from a git perspective as well. There's a s Everything you do here is contained within this one codespace. There is no repository on GitHub yet. If and when you’re ready you can click "Publish Branch" and we’ll create your repository and push up your project. If you were just exploring then and have no further need for this code then you can simply delete your codespace and it's gone forever. -### to generate secretkey for djanggo project run +### to generate secretkey for django project run ```python python secretgen.py From de14e9499700d13ab270a88f8a4619d7bda915b5 Mon Sep 17 00:00:00 2001 From: martcpp Date: Tue, 12 Mar 2024 12:54:59 +0100 Subject: [PATCH 4/4] added a script tto generate serect key --- .env.example | 2 +- hello_world/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index c78ddce..687d9a5 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -SECRET_KEY=my_secret_key +SECRET_KEY= replace with your secret key DEBUG=True # Database diff --git a/hello_world/settings.py b/hello_world/settings.py index 92cebe5..545d430 100644 --- a/hello_world/settings.py +++ b/hello_world/settings.py @@ -25,7 +25,7 @@ # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = os.getenv('my_secret_key') +SECRET_KEY = os.getenv('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = os.getenv("DEBUG")