Add django base web application#161
Merged
La0 merged 4 commits intomozilla:masterfrom Oct 18, 2019
Merged
Conversation
This was referenced Oct 18, 2019
La0
commented
Oct 18, 2019
Comment on lines
+140
to
+175
| # Static files are set in a dedicated path in Docker image | ||
| if "DJANGO_DOCKER" in os.environ: | ||
| STATIC_ROOT = "/static" | ||
|
|
||
| # Enable GZip and cache, and build a manifest during collectstatic | ||
| STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" | ||
|
|
||
|
|
||
| # Internal logging setup | ||
| LOGGING = { | ||
| "version": 1, | ||
| "disable_existing_loggers": False, | ||
| "handlers": {"console": {"class": "logging.StreamHandler"}}, | ||
| "loggers": { | ||
| "django": {"handlers": ["console"], "level": "INFO"}, | ||
| "code_review_backend": {"handlers": ["console"], "level": "INFO"}, | ||
| }, | ||
| } | ||
|
|
||
| # Heroku settings override to run the web app in production mode | ||
| if "DYNO" in os.environ: | ||
| logger.info("Setting up Heroku environment") | ||
| ALLOWED_HOSTS = ["*"] | ||
| DEBUG = os.environ.get("DEBUG", "false").lower() == "true" | ||
|
|
||
| # Database setup | ||
| if "DATABASE_URL" in os.environ: | ||
| logger.info("Using remote database from $DATABASE_URL") | ||
| DATABASES["default"] = dj_database_url.parse( | ||
| os.environ["DATABASE_URL"], ssl_require=True | ||
| ) | ||
| else: | ||
| logger.info("DATABASE_URL not found, will use sqlite. Data may be lost.") | ||
|
|
||
| # Insert Whitenoise Middleware after the security one | ||
| MIDDLEWARE.insert(1, "whitenoise.middleware.WhiteNoiseMiddleware") |
Collaborator
Author
There was a problem hiding this comment.
Added these lines to run on Heroku
La0
commented
Oct 18, 2019
Comment on lines
+122
to
+132
| # API configuration | ||
| REST_FRAMEWORK = { | ||
| # Use Django's standard `django.contrib.auth` permissions, | ||
| # or allow read-only access for unauthenticated users. | ||
| "DEFAULT_PERMISSION_CLASSES": [ | ||
| "rest_framework.permissions.IsAuthenticatedOrReadOnly" | ||
| ], | ||
| # Setup pagination | ||
| "PAGE_SIZE": 50, | ||
| "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.LimitOffsetPagination", | ||
| } |
La0
commented
Oct 18, 2019
| "django.contrib.sessions", | ||
| "django.contrib.messages", | ||
| "django.contrib.staticfiles", | ||
| "rest_framework", |
Collaborator
Author
There was a problem hiding this comment.
Added that line to load DRF
marco-c
reviewed
Oct 18, 2019
| SECRET_KEY = "t!+s!@x5p!85x19q83jufr#95_z0fv7$!u5z*c&gi!%hr3^w+r" | ||
|
|
||
| # SECURITY WARNING: don't run with debug turned on in production! | ||
| DEBUG = True |
Collaborator
There was a problem hiding this comment.
Can you add a comment here to explain that, for production, this is overwritten in the Heroku section at the end of the file?
marco-c
reviewed
Oct 18, 2019
| # SECURITY WARNING: keep the secret key used in production secret! | ||
| SECRET_KEY = os.environ.get( | ||
| "SECRET_KEY", "t!+s!@x5p!85x19q83jufr#95_z0fv7$!u5z*c&gi!%hr3^w+r" | ||
| ) |
Collaborator
There was a problem hiding this comment.
Maybe you could move the env part to the Heroku section too, so you have the same behavior as for DEBUG
marco-c
approved these changes
Oct 18, 2019
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add an empty django web application, shipped through CI/CD