def update_files_dictionary(self, *args):
super(SPAMiddleware, self).update_files_dictionary(*args)
index_page_suffix = '/' + self.index_name
index_name_length = len(self.index_name)
static_prefix_length = len(settings.STATIC_URL) - 1
directory_indexes = {}
for url, static_file in self.files.items():
if url.endswith(index_page_suffix):
# For each index file found, add a corresponding URL->content
# mapping for the file's parent directory,
# so that the index page is served for
# the bare directory URL ending in '/'.
parent_directory_url = url[:-index_name_length]
directory_indexes[parent_directory_url] = static_file
# remember the root page for any other unrecognised files
# to be frontend-routed
self.spa_root = static_file
else:
# also serve static files on /
# e.g. serve /static/my/file.png on /my/file.png
directory_indexes[url[static_prefix_length:]] = static_file
self.files.update(directory_indexes)
评论列表
文章目录