Skip to content

Add django base web application#161

Merged
La0 merged 4 commits intomozilla:masterfrom
La0:backend-base
Oct 18, 2019
Merged

Add django base web application#161
La0 merged 4 commits intomozilla:masterfrom
La0:backend-base

Conversation

@La0
Copy link
Copy Markdown
Collaborator

@La0 La0 commented Oct 18, 2019

Add an empty django web application, shipped through CI/CD

@La0 La0 requested a review from marco-c October 18, 2019 09:46
@La0 La0 self-assigned this 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")
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added these lines to run on Heroku

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",
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Config for the API (could be in #162)

"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"rest_framework",
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added that line to load DRF

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you add a comment here to explain that, for production, this is overwritten in the Heroku section at the end of the file?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

# 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"
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe you could move the env part to the Heroku section too, so you have the same behavior as for DEBUG

@La0 La0 merged commit fa80fe5 into mozilla:master Oct 18, 2019
@La0 La0 deleted the backend-base branch October 18, 2019 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants