本文整理汇总了Python中django.forms.util.ErrorDict.as_text方法的典型用法代码示例。如果您正苦于以下问题:Python ErrorDict.as_text方法的具体用法?Python ErrorDict.as_text怎么用?Python ErrorDict.as_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms.util.ErrorDict
的用法示例。
在下文中一共展示了ErrorDict.as_text方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: error
# 需要导入模块: from django.forms.util import ErrorDict [as 别名]
# 或者: from django.forms.util.ErrorDict import as_text [as 别名]
def error(
self,
request,
status_code,
error_dict=None,
):
"""
Handles errors in a RESTful way.
- appropriate status code
- appropriate mimetype
- human-readable error message
"""
if not error_dict:
error_dict = ErrorDict()
response = HttpResponse(mimetype=self.mimetype)
response.write('%d %s' % (status_code,
STATUS_CODE_TEXT[status_code]))
if error_dict:
response.write('''
Errors:
''')
response.write(error_dict.as_text())
response.status_code = status_code
return response
示例2: error_response
# 需要导入模块: from django.forms.util import ErrorDict [as 别名]
# 或者: from django.forms.util.ErrorDict import as_text [as 别名]
def error_response( error_code, error_message, error_class, error_dict = None):
resp_dict = {}
# response = HttpResponse()
response = HttpResponseServerError()
resp_dict['error code'] = error_code
resp_dict['error message'] = error_message
resp_dict['error class'] = error_class
# if error_code == 500:
# response.status_code = error_code
if error_dict:
error_dict = ErrorDict(error_dict)
resp_dict['error message'] += '\n%s'%error_dict.as_text()
logger.debug('resp_dict%s' %resp_dict)
response.write(json.dumps(resp_dict))
logger.debug('response.content %s' %response.content)
return response