对你的问题的回答是错误的。如果你这样做,你会得到下一个错误:
ImproperlyConfigured: Your STATICFILES_DIRS setting is not a tuple or list; perhaps you forgot a trailing comma?
我的决定是在 settings.py 文件的顶部添加下一个函数:
导入操作系统
def look_folder_tree(根):
结果 = ()
对于 os.walk(root) 中的 dir_name、sub_dirs、file_names:
对于 sub_dirs 中的 sub_dir_name:
结果 += (os.path.join(dir_name, sub_dir_name),)
返回结果
# 项目的 Django 设置。
PROJECT_DIR = os.path.dirname(__file__)
并在以下位置调用look_folder_tree函数:
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = look_folder_tree(STATIC_ROOT)
我的决定是允许在静态目录中添加所有子文件夹。