update static url settings

This commit is contained in:
2026-06-09 16:00:58 +08:00
parent 2b86c91edd
commit 1dc9141856
2 changed files with 9 additions and 2 deletions
+5 -2
View File
@@ -239,12 +239,15 @@ def _build_banner_url(request, banner_value):
- 空值回退到 settings.DEFAULT_INSTITUTION_BANNER
- 已是 http(s) 完整 URL 时原样返回
- 否则视为相对 STATIC_URL 的静态路径,拼成绝对 URL
- 否则视为相对 STATIC_URL 的静态路径,拼成绝对 URL
若配置了 settings.STATIC_PUBLIC_PREFIX(如线上 '/server'),则补在前面,
以适配 Nginx 砍掉 /server 子路径前缀的部署。
"""
value = banner_value or settings.DEFAULT_INSTITUTION_BANNER
if value.startswith(('http://', 'https://')):
return value
path = '/' + settings.STATIC_URL.strip('/') + '/' + value.lstrip('/')
prefix = settings.STATIC_PUBLIC_PREFIX.rstrip('/')
path = prefix + '/' + settings.STATIC_URL.strip('/') + '/' + value.lstrip('/')
return request.build_absolute_uri(path)