File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3939IS_LOCAL = os .getenv ("IS_LOCAL" , "0" ) == "1"
4040print (f"IS_LOCAL={ IS_LOCAL } " )
4141
42- VERSION = os .getenv ("VERSION" , "N/A" )
43-
4442CSRF_TRUSTED_ORIGINS = []
4543
4644for host in ALLOWED_HOSTS :
Original file line number Diff line number Diff line change 44Provides a simple health check that returns the current application version.
55"""
66
7- from django .conf import settings
7+ import os
8+ import tomllib
9+ from pathlib import Path
10+
811from django .http import JsonResponse
912
1013
14+ def get_version ():
15+ """Read version from pyproject.toml."""
16+ pyproject_path = Path (__file__ ).parent .parent .parent / "pyproject.toml"
17+ try :
18+ with open (pyproject_path , "rb" ) as f :
19+ data = tomllib .load (f )
20+ return data .get ("project" , {}).get ("version" , "unknown" )
21+ except Exception :
22+ return "unknown"
23+
24+
1125def health_view (request ):
1226 """
1327 Health check endpoint that returns the current version.
@@ -17,5 +31,5 @@ def health_view(request):
1731 """
1832 return JsonResponse ({
1933 "status" : "ok" ,
20- "version" : getattr ( settings , "VERSION" , "unknown" ),
34+ "version" : get_version ( ),
2135 })
You can’t perform that action at this time.
0 commit comments