我已经在我的 django 应用程序中设置了静态和媒体根以及 url,如下所示:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
MEDIA_URL = '/crl/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'config/crl/')
它运行良好,但我想添加另一个 MEDIA_URL 和 MEDIA_ROOT 来提供来自
/certs/
的文件目录如下:NEW_MEDIA_URL = '/certs/'
NEW_MEDIA_ROOT = os.path.join(BASE_DIR, 'config/certs/')
有什么办法吗?
我正在使用 Django 2.0.6 和 Python 3.5
最佳答案
可以使用以下步骤将多个静态 URL 和静态根添加到 Django。
BASE_DIR
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
# the "static/" above is a directory inside the Django Project Directory
STATIC_URL_1 = '/static-1/'
STATIC_ROOT_1 = os.path.join(BASE_DIR, "static_1/")
MEDIA_URL = '/crl/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'config/crl/')
MEDIA_URL_1 = '/crl-1/'
MEDIA_ROOT_1 = os.path.join(BASE_DIR, 'config/crl_1/')
关于django - 在 Django 中设置多个 MEDIA_URL 和 MEDIA_ROOT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51802022/