update static url settings
This commit is contained in:
+5
-2
@@ -239,12 +239,15 @@ def _build_banner_url(request, banner_value):
|
|||||||
|
|
||||||
- 空值回退到 settings.DEFAULT_INSTITUTION_BANNER
|
- 空值回退到 settings.DEFAULT_INSTITUTION_BANNER
|
||||||
- 已是 http(s) 完整 URL 时原样返回
|
- 已是 http(s) 完整 URL 时原样返回
|
||||||
- 否则视为相对 STATIC_URL 的静态路径,拼成绝对 URL
|
- 否则视为相对 STATIC_URL 的静态路径,拼成绝对 URL;
|
||||||
|
若配置了 settings.STATIC_PUBLIC_PREFIX(如线上 '/server'),则补在前面,
|
||||||
|
以适配 Nginx 砍掉 /server 子路径前缀的部署。
|
||||||
"""
|
"""
|
||||||
value = banner_value or settings.DEFAULT_INSTITUTION_BANNER
|
value = banner_value or settings.DEFAULT_INSTITUTION_BANNER
|
||||||
if value.startswith(('http://', 'https://')):
|
if value.startswith(('http://', 'https://')):
|
||||||
return value
|
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)
|
return request.build_absolute_uri(path)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,10 @@ USE_TZ = True
|
|||||||
STATIC_URL = 'static/'
|
STATIC_URL = 'static/'
|
||||||
STATICFILES_DIRS = [BASE_DIR / 'static']
|
STATICFILES_DIRS = [BASE_DIR / 'static']
|
||||||
|
|
||||||
|
# 静态资源公网前缀:本地直连为空;线上 Nginx 把应用挂在 /server 子路径下时设为 '/server'
|
||||||
|
# (只用于生成对外可访问的静态 URL,不改变 Django 实际提供文件的路径)
|
||||||
|
STATIC_PUBLIC_PREFIX = os.getenv('STATIC_PUBLIC_PREFIX', '')
|
||||||
|
|
||||||
# 机构 Banner 默认图(当 Institution.banner_url 为空时回退使用,相对 STATIC_URL)
|
# 机构 Banner 默认图(当 Institution.banner_url 为空时回退使用,相对 STATIC_URL)
|
||||||
DEFAULT_INSTITUTION_BANNER = 'institutions/default_hospital.png'
|
DEFAULT_INSTITUTION_BANNER = 'institutions/default_hospital.png'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user