读取其他文件时返回多个版本异常

时间:2017-01-17 05:49:25

标签: python django python-2.7 read-the-docs

Django版本:1.8.16 Python版本:2.7.5

所有文档都是公开的,即使您没有登录也可以阅读所有文档,但是当您登录时,如果您没有超级管理员权限,则会显示错误消息

异常

Request Method: GET
Request URL:    http://rtd.chan.net/en/latest/
Django Version: 1.8.16
Exception Type: MultipleObjectsReturned
Exception Value:    
get() returned more than one Version -- it returned 2!
Exception Location: /www/rtd/lib/python2.7/site-packages/django/db/models/query.py in get, line 338
Python Executable:  /www/rtd/bin/uwsgi
Python Version: 2.7.5
Python Path:    
['.',
 '',
 '/www/rtd/lib64/python27.zip',
 '/www/rtd/lib64/python2.7',
 '/www/rtd/lib64/python2.7/plat-linux2',
 '/www/rtd/lib64/python2.7/lib-tk',
 '/www/rtd/lib64/python2.7/lib-old',
 '/www/rtd/lib64/python2.7/lib-dynload',
 '/usr/lib64/python2.7',
 '/usr/lib/python2.7',
 '/www/rtd/lib/python2.7/site-packages']

代码

def get(self, *args, **kwargs):
    """
    Performs the query and returns a single object matching the given
    keyword arguments.
    """
    clone = self.filter(*args, **kwargs)
    if self.query.can_filter():
        clone = clone.order_by()
    num = len(clone)
    if num == 1:
        return clone._result_cache[0]
    if not num:
        raise self.model.DoesNotExist(
            "%s matching query does not exist." %
            self.model._meta.object_name
        )
    raise self.model.MultipleObjectsReturned(
        "get() returned more than one %s -- it returned %s!" %
        (self.model._meta.object_name, num)
    )

第338行是(self.model._meta.object_name, num)

我尝试向Google发送异常消息,编码解决方案是将get更改为filter,但它会导致另一个异常,我不认为这是真正的解决方案,如何修复它?

0 个答案:

没有答案