我正在使用Django Rest Framework来构建一个 api,并在我的开发机器上实现了。我今天想快速部署它,事实证明它比我预期的更容易出错。我重新安装了依赖项,重新安装了 Django,花了几个小时寻找错误,但是这个最新的已经打败了我和谷歌。
在开发机器上,当我从框架调用其中一个视图时,我得到了正确的响应(减去静态文件,但我稍后会处理。)然而,在部署机器上,我得到了这个错误:
'SplitResult' object has no attribute '_replace'
回溯通过rest框架中的一个模板标签,但是这个方法中的urlobject中似乎抛出了错误:
def __replace(self, **replace):
"""Replace a field in the ``urlparse.SplitResult`` for this URL."""
return type(self)(urlparse.urlunsplit(
urlparse.urlsplit(self)._replace(**replace)))
我无法在我的开发机器上重现此错误,并且在任何地方都找不到对此错误的任何引用。以防万一我在部署服务器上使用 Django 1.2、1.3 和 1.4 进行了尝试,但该错误似乎与 Django 本身无关。
这是完整的回溯:
Django Version: 1.3.1
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'char',
'djangorestframework']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.5/site-packages/django/views/generic/base.py" in view
47. return self.dispatch(request, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/views/decorators/csrf.py" in wrapped_view
39. resp = view_func(*args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/views/decorators/csrf.py" in wrapped_view
52. return view_func(*args, **kwargs)
File "/home/wfrp/wfrp-django/DjangoWfrp/external apps/django-rest-framework/djangorestframework/views.py" in dispatch
243. return self.final(request, response, *args, **kwargs)
File "/home/wfrp/wfrp-django/DjangoWfrp/external apps/django-rest-framework/djangorestframework/views.py" in final
196. return self.render(response)
File "/home/wfrp/wfrp-django/DjangoWfrp/external apps/django-rest-framework/djangorestframework/mixins.py" in render
251. content = renderer.render(response.cleaned_content, media_type)
File "/home/wfrp/wfrp-django/DjangoWfrp/external apps/django-rest-framework/djangorestframework/renderers.py" in render
351. ret = template.render(context)
File "/usr/lib/python2.5/site-packages/django/template/base.py" in render
123. return self._render(context)
File "/usr/lib/python2.5/site-packages/django/template/base.py" in _render
117. return self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/base.py" in render_node
757. return node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/loader_tags.py" in render
127. return compiled_parent._render(context)
File "/usr/lib/python2.5/site-packages/django/template/base.py" in _render
117. return self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/base.py" in render_node
757. return node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py" in render
311. return self.nodelist_true.render(context)
File "/usr/lib/python2.5/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/base.py" in render_node
757. return node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py" in render
227. nodelist.append(node.render(context))
File "/usr/lib/python2.5/site-packages/django/template/defaulttags.py" in render
500. output = self.nodelist.render(context)
File "/usr/lib/python2.5/site-packages/django/template/base.py" in render
744. bits.append(self.render_node(node, context))
File "/usr/lib/python2.5/site-packages/django/template/base.py" in render_node
757. return node.render(context)
File "/usr/lib/python2.5/site-packages/django/template/base.py" in render
792. output = self.filter_expression.resolve(context)
File "/usr/lib/python2.5/site-packages/django/template/base.py" in resolve
536. new_obj = func(obj, *arg_vals)
File "/home/wfrp/wfrp-django/DjangoWfrp/external apps/django-rest-framework/djangorestframework/templatetags/add_query_param.py" in add_query_param
7. return unicode(URLObject(url).with_query(param))
File "/home/wfrp/wfrp-django/DjangoWfrp/external apps/urlobject/lib/urlobject/urlobject.py" in with_query
117. return self.__replace(query=query)
File "/home/wfrp/wfrp-django/DjangoWfrp/external apps/urlobject/lib/urlobject/urlobject.py" in __replace
181. urlparse.urlsplit(self)._replace(**replace)))
Exception Type: AttributeError at /api/
Exception Value: 'SplitResult' object has no attribute '_replace'
这是我第一次使用 Stack Overflow — 感谢您的帮助。