-
Notifications
You must be signed in to change notification settings - Fork 154
🔧 Split Settings into Development and Production Environments and updating the requirements #44
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
Open
snipher-marube
wants to merge
5
commits into
github:main
Choose a base branch
from
snipher-marube:update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bde1e98
updating the requirements
snipher-marube e1d6c6f
updating the requirements
snipher-marube 0c266e6
separated the settings for production and development
snipher-marube 298823a
separated the settings for production and development
snipher-marube 7c5628a
separated the settings for production and development
snipher-marube File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import os | ||
|
|
||
| settings_module = os.getenv('DJANGO_SETTINGS_MODULE') | ||
|
|
||
| if settings_module == 'hello_world.settings.production': | ||
| from .production import * | ||
| elif settings_module == 'hello_world.settings.development': | ||
| from .development import * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| """ | ||
| Base Django settings for hello_world project (shared across all environments). | ||
| """ | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
| from decouple import config | ||
|
|
||
| BASE_DIR = Path(__file__).resolve().parent.parent | ||
|
|
||
| SECRET_KEY = config("SECRET_KEY", default="your-secret-key") | ||
|
|
||
| # Can be overridden in dev/prod settings | ||
| ALLOWED_HOSTS = config("ALLOWED_HOSTS", default="").split(",") | ||
|
|
||
| INSTALLED_APPS = [ | ||
| "django.contrib.admin", | ||
| "django.contrib.auth", | ||
| "django.contrib.contenttypes", | ||
| "django.contrib.sessions", | ||
| "django.contrib.messages", | ||
| "django.contrib.staticfiles", | ||
| "django_browser_reload", | ||
| ] | ||
|
|
||
| MIDDLEWARE = [ | ||
| "django.middleware.security.SecurityMiddleware", | ||
| "django.contrib.sessions.middleware.SessionMiddleware", | ||
| "django.middleware.common.CommonMiddleware", | ||
| "django.middleware.csrf.CsrfViewMiddleware", | ||
| "django.contrib.auth.middleware.AuthenticationMiddleware", | ||
| "django.contrib.messages.middleware.MessageMiddleware", | ||
| "django.middleware.clickjacking.XFrameOptionsMiddleware", | ||
| "django_browser_reload.middleware.BrowserReloadMiddleware", | ||
| ] | ||
|
|
||
| X_FRAME_OPTIONS = "ALLOW-FROM preview.app.github.dev" | ||
|
|
||
| ROOT_URLCONF = "hello_world.urls" | ||
|
|
||
| TEMPLATES = [ | ||
| { | ||
| "BACKEND": "django.template.backends.django.DjangoTemplates", | ||
| "DIRS": [BASE_DIR / "templates"], | ||
| "APP_DIRS": True, | ||
| "OPTIONS": { | ||
| "context_processors": [ | ||
| "django.template.context_processors.debug", | ||
| "django.template.context_processors.request", | ||
| "django.contrib.auth.context_processors.auth", | ||
| "django.contrib.messages.context_processors.messages", | ||
| ], | ||
| }, | ||
| }, | ||
| ] | ||
|
|
||
| WSGI_APPLICATION = "hello_world.wsgi.application" | ||
|
|
||
| AUTH_PASSWORD_VALIDATORS = [ | ||
| {"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"}, | ||
| {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"}, | ||
| {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"}, | ||
| {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"}, | ||
| ] | ||
|
|
||
| LANGUAGE_CODE = "en-us" | ||
| TIME_ZONE = "UTC" | ||
| USE_I18N = True | ||
| USE_TZ = True | ||
|
|
||
| STATICFILES_DIRS = [BASE_DIR / "static"] | ||
| STATIC_URL = "static/" | ||
| STATIC_ROOT = BASE_DIR / "staticfiles" | ||
|
|
||
| MEDIA_URL = "media/" | ||
| MEDIA_ROOT = BASE_DIR / "media" | ||
|
|
||
| DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from .base import * | ||
| import os | ||
|
|
||
| DEBUG = True | ||
|
|
||
| ALLOWED_HOSTS = ["localhost", "127.0.0.1"] | ||
| CSRF_TRUSTED_ORIGINS = ["http://localhost:8000", "http://127.0.0.1"] | ||
|
|
||
| # Support for GitHub Codespaces | ||
| if 'CODESPACE_NAME' in os.environ: | ||
| from decouple import config | ||
| codespace_name = config("CODESPACE_NAME") | ||
| domain = config("GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN") | ||
| codespace_host = f"{codespace_name}-8000.{domain}" | ||
| ALLOWED_HOSTS.append(codespace_host) | ||
| CSRF_TRUSTED_ORIGINS.append(f"https://{codespace_host}") | ||
|
|
||
| DATABASES = { | ||
| "default": { | ||
| "ENGINE": "django.db.backends.sqlite3", | ||
| "NAME": BASE_DIR / "db.sqlite3", | ||
| "OPTIONS": { | ||
| "timeout": 20, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| SECURE_SSL_REDIRECT = False | ||
| SESSION_COOKIE_SECURE = False | ||
| CSRF_COOKIE_SECURE = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| from .base import * | ||
| from decouple import config | ||
|
|
||
| DEBUG = False | ||
|
|
||
| ALLOWED_HOSTS = config("ALLOWED_HOSTS", default="yourdomain.com").split(",") | ||
| CSRF_TRUSTED_ORIGINS = config("CSRF_TRUSTED_ORIGINS", default="https://yourdomain.com").split(",") | ||
|
|
||
| DATABASES = { | ||
| "default": { | ||
| "ENGINE": "django.db.backends.postgresql", | ||
| "NAME": config("DB_NAME"), | ||
| "USER": config("DB_USER"), | ||
| "PASSWORD": config("DB_PASSWORD"), | ||
| "HOST": config("DB_HOST", default="localhost"), | ||
| "PORT": config("DB_PORT", default="5432"), | ||
| } | ||
| } | ||
|
|
||
| SECURE_SSL_REDIRECT = True | ||
| SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") | ||
| SECURE_HSTS_SECONDS = 31536000 | ||
| SECURE_HSTS_INCLUDE_SUBDOMAINS = True | ||
| SECURE_HSTS_PRELOAD = True | ||
| SECURE_BROWSER_XSS_FILTER = True | ||
| SECURE_CONTENT_TYPE_NOSNIFF = True | ||
| SECURE_REFERRER_POLICY = "strict-origin-when-cross-origin" | ||
| SESSION_COOKIE_SECURE = True | ||
| CSRF_COOKIE_SECURE = True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| asgiref~=3.8.1 | ||
| Django~=5.0.8 | ||
| django-browser-reload~=1.13.0 | ||
| Django~=5.2 | ||
| django-browser-reload~=1.18.0 | ||
| python-decouple~=3.8 | ||
| sqlparse~=0.5.1 | ||
| sqlparse~=0.5.3 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the main() function imports the development settings first to check DEBUG, which may lead to confusion when switching to production. Consider using an environment variable or another configuration flag to determine the settings module prior to importing any settings.