Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the a scripts help generate secret key #34

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
SECRET_KEY=my_secret_key
SECRET_KEY= replace with your secret key
Copy link
Collaborator

@joshaber joshaber Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about generating the secret as part of the postCreateCommand, so that devs don't have to manually do anything? The script is definitely an improvement, but ideally folks wouldn't have to know/care about generating the secret.

Copy link
Author

@martcpp martcpp Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i taught of doing this but i feel incase of doing a cloud uploading must time people need to document or change their secret keys reason i added it as script @joshaber

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
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 django 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
Expand Down
5 changes: 3 additions & 2 deletions hello_world/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand All @@ -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 = os.getenv('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv("DEBUG")

ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', '').split(',')
ALLOWED_HOSTS = ["*"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the motivation for moving this into here, instead of keeping it in .env?

Copy link
Author

@martcpp martcpp Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is easy to access rather than keeping it in .env file and other will know it part of the setting as we don't push .env to GitHub @joshaber


if 'CODESPACE_NAME' in os.environ:
codespace_name = os.getenv("CODESPACE_NAME")
Expand Down
7 changes: 7 additions & 0 deletions secretgen.py
Original file line number Diff line number Diff line change
@@ -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)