File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ dependencies = [
6666 " django-filter==25.1" ,
6767 " django-cors-headers==4.9.0" ,
6868 " nh3==0.3.3" ,
69+ " configobj==5.0.9" ,
6970]
7071
7172[tool .uv ]
Original file line number Diff line number Diff line change 55from celery import signals
66import dj_database_url
77from .logs_loguru import configure_logging
8+ from django .core .management .utils import get_random_secret_key
9+ import configobj
810
911
1012BASE_DIR = os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
125127USE_I18N = True
126128USE_L10N = True
127129USE_TZ = True
128- SECRET_KEY = os .environ .get ("SECRET_KEY" , '(*0&74%ihg0ui+400+@%2pe92_c)x@w2m%6s(jhs^)dc$&&g93' )
130+
131+ # =============================================================================
132+ # Secret key (generate one if none is given, otherwise use given key)
133+ # =============================================================================
134+ # This is needed when the secret key is generated for the first time as it won't be loaded as an environment variable
135+ config = configobj .ConfigObj ('.env' )
136+ with open (".env" , "a+" ) as f :
137+ secret_key_count = 0
138+ f .seek (0 )
139+ for x in f :
140+ if "SECRET_KEY=" in x and x [0 ] == "S" :
141+ secret_key_count = 1
142+ SECRET_KEY = os .environ .get ("SECRET_KEY" , config ['SECRET_KEY' ])
143+ break
144+ if secret_key_count == 0 :
145+ SECRET_KEY = get_random_secret_key ()
146+ f .write (f"SECRET_KEY='{ SECRET_KEY } '" )
147+ f .close ()
148+
129149LOGIN_REDIRECT_URL = '/'
130150LOGOUT_REDIRECT_URL = '/'
131151
You can’t perform that action at this time.
0 commit comments