本文整理匯總了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