好吧,在代码中稍作改动表明,在此过程中可能存在更深层次的错误消息。
在django / core / files / storage.py中,第210行(在1.1.1中),我们有:
def path(self, name): try: path = safe_join(self.location, name) except ValueError: raise SuspiciousOperation("Attempted access to '%s' denied." % name) return smart_str(os.path.normpath(path))因此错误必须来自safe_join()。
在django / utils / _os.py中,我们有以下内容。请注意它抛出的ValueError在倒数第三行:
==========================
def safe_join(base, *paths): """ Joins one or more path components to the base path component intelligently. Returns a normalized, absolute version of the final path. The final path must be located inside of the base path component (otherwise a ValueError is raised). """ # We need to use normcase to ensure we don't false-negative on case # insensitive operating systems (like Windows). base = force_unipre(base) paths = [force_unipre(p) for p in paths] final_path = normcase(abspathu(join(base, *paths))) base_path = normcase(abspathu(base)) base_path_len = len(base_path) # Ensure final_path starts with base_path and that the next character after # the final path is os.sep (or nothing, in which case final_path must be # equal to base_path). if not final_path.startswith(base_path) or final_path[base_path_len:base_path_len+1] not in ('', sep): raise ValueError('the joined path is located outside of the base path' ' component') return final_path==================
嗯,“连接的路径位于基本路径组件的外部”。现在在那里有几个对abspathu()的调用(在该例程的上方定义,并且NT与其他OS有所不同)。abspathu()通过添加当前工作目录os.cwdu()将所有非绝对路径转换为绝对路径。
问题:您是否有任何指向媒体目录的符号链接(符号链接)?换句话说,它不是项目目录的直接子目录吗?我不知道这是否是一个有效的问题,只是从我脑海中浮现。
问:什么 是 值
self.location和
name正在传递到safe_join()?
野驴猜:是
self.location空的吗?
另一个疯狂的猜测:MEDIA_ROOT是否以某种方式变为
/media/?
如果您安装了自己的Django副本(这并不难),请尝试在这些例程中放入一些打印语句,然后将其作为开发服务器运行。打印输出将进入控制台。
更新: 嗯。您说:“ 2)self.location和名称的值为:/ home / tsoporan / site /
media和/media/albums/anthem-for-the-underdog/30103635.jpg”
以下路径有意义吗?
"/home/tsoporan/site/media/media/albums/anthem-for-the-underdog"
注意其中的… / media / media /…。
另外,这是什么操作系统?Django版本?



