有没有办法将我的django-tenant模式名称添加到MEDIA_ROOT?

时间:2020-09-28 07:50:34

标签: django geodjango

我修改了我的Geonode项目(这是一个GeoDjango项目),以使用django-tenant启用多租户。由于路由中断,我目前无法查看缩略图...

如何正确路由生成的缩略图,例如:http://d3.demo.com(current_tenant_domain_url)/ uploaded / d3(tenant)/ thumbs / document-8a72dc8c-0151-11eb-a488-1062e5032d68-thumb。 png

当前生成的缩略图URL如下:http:// localhost:8000 / uploaded / thumbs / document-fcdea3a4-015c-11eb-a488-1062e5032d68-thumb.png?v = c1855f6a

urls.py

  urlpatterns += staticfiles_urlpatterns()
    urlpatterns += static(settings.LOCAL_MEDIA_URL,
                          document_root=settings.MEDIA_ROOT)

我当前的设置。py

MEDIA_ROOT = os.getenv('MEDIA_ROOT', os.path.join(PROJECT_ROOT, MEDIAFILES_LOCATION))

MEDIA_URL = os.getenv('MEDIA_URL', '%s/%s/%s/' % (FORCE_SCRIPT_NAME, MEDIAFILES_LOCATION, MULTITENANT_RELATIVE_MEDIA_ROOT))

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

settings.py

MIDDLEWARE = [
    'django_tenants.middleware.main.TenantMainMiddleware'
]

DATABASE_ROUTERS = (
    'django_tenants.routers.TenantSyncRouter',
)

STATIC_URL = '/static/'
STATIC_ROOT = 'staticfiles'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

MEDIA_URL = '/media/'
DEFAULT_FILE_STORAGE = 'django_tenants.files.storages.TenantFileSystemStorage'
MEDIA_ROOT = os.path.join(BASE_DIR, 'public', 'media')

urls.py

urlpatterns = [...] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)