diff --git a/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py b/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py index 14c6fa4..d1e5225 100644 --- a/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py +++ b/shimatta_kenkyusho/shimatta_kenkyusho/settings_production.py @@ -17,6 +17,8 @@ The following environment variables have to be set: - DJANGO_MEDIA_ROOT - DJANGO_POSTGRESQL_SOCKET +The following can be set +- DJANGO_SECURE_HSTS_SECONDS (defaults to 120) """ @@ -26,11 +28,13 @@ import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent -def get_env_value(env_variable): +def get_env_value(env_variable, default=None): try: return os.environ[env_variable] except KeyError: - error_msg = 'Set the {} environment variable'.format(env_variable) + if default is not None: + return default + error_msg = 'Set the {} environment variable'.format(env_variable) raise Exception(error_msg) @@ -225,4 +229,6 @@ CRISPY_TEMPLATE_PACK = "bootstrap5" SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True -SECURE_SSL_REDIRECT = True \ No newline at end of file +SECURE_SSL_REDIRECT = True + +SECURE_HSTS_SECONDS = get_env_value('DJANGO_SECURE_HSTS_SECONDS', default=120) \ No newline at end of file