Skip to content

allow setting django secret with enironment variable #8566

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

Merged
merged 4 commits into from
Jan 23, 2025
Merged
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
4 changes: 4 additions & 0 deletions changelog.d/20250123_161129_pr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Added

- Ability to set Django's secret key using an environment variable
(<https://github.com/cvat-ai/cvat/pull/8566>)
14 changes: 8 additions & 6 deletions cvat/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', 'localhost,127.0.0.1').split(',')
INTERNAL_IPS = ['127.0.0.1']
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY", "")

def generate_secret_key():
"""
Expand Down Expand Up @@ -72,12 +73,13 @@ def generate_secret_key():
# Discard ours and use theirs.
pass

try:
sys.path.append(BASE_DIR)
from keys.secret_key import SECRET_KEY # pylint: disable=unused-import
except ModuleNotFoundError:
generate_secret_key()
from keys.secret_key import SECRET_KEY
if not SECRET_KEY:
try:
sys.path.append(BASE_DIR)
from keys.secret_key import SECRET_KEY # pylint: disable=unused-import
except ModuleNotFoundError:
generate_secret_key()
from keys.secret_key import SECRET_KEY

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
INSTALLED_APPS = [
Expand Down
Loading