这有效:
class Right(ResponseMixin, View):
"""Right"""
renderers = (JSONRenderer, XMLRenderer)
def get(self, request, right_id):
if not right_id:
return self.render(
Response(status.HTTP_400_BAD_REQUEST,
{"successful": False})
)
这不会:
class Right(ResponseMixin, View):
"""Right"""
renderers = (JSONRenderer, XMLRenderer)
# @default_json
def get(self, request, right_id):
if not right_id:
raise ErrorResponse(status.HTTP_400_BAD_REQUEST,
{"successful": False})
我收到一条错误消息,上面写着:
/v1/right/ 处的 ErrorResponse 未提供异常
或者:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/v1/right/
Django Version: 1.4.1
Python Version: 2.7.2
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles')
Installed Middleware:
('api.disable.DisableCSRF',
'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 "/Users/agoodattitude/Envs/locker-proxy/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/agoodattitude/Envs/locker-proxy/lib/python2.7/site-packages/django/views/generic/base.py" in view
48. return self.dispatch(request, *args, **kwargs)
File "/Users/agoodattitude/Envs/locker-proxy/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
69. return handler(request, *args, **kwargs)
File "/Users/agoodattitude/saff-py/locker-proxy/locker_proxy/api/resources.py" in get
125. error_message="right_id was not passed."))
Exception Type: ErrorResponse at /v1/right/
Exception Value:
有人知道“不提供例外”是什么意思吗?
(注意,我稍微更改了代码以降低复杂性,但问题仍然存在......)