本文整理汇总了Python中pyramid.response.Response.status_string方法的典型用法代码示例。如果您正苦于以下问题:Python Response.status_string方法的具体用法?Python Response.status_string怎么用?Python Response.status_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response.Response
的用法示例。
在下文中一共展示了Response.status_string方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_string [as 别名]
def upload(request):
if request.content_length/1000000 > 20:
return error_response(400, 'Sorry, but the file must be under 20MB.')
# Create photo object in database
photo = Photo(datetime.today(), request.POST['file'].filename, request.client_addr, request.content_type, request.content_length)
DBSession.add(photo)
DBSession.flush()
# Save uploaded file
input_file = request.POST['file'].file
input_file.seek(0)
if not os.path.exists('data'):
os.makedirs('data')
if not os.path.exists('data/uploads'):
os.makedirs('data/uploads')
upload_path = os.path.join('data', 'uploads', str(photo.id))
with open(upload_path, 'w') as f:
shutil.copyfileobj(input_file, f)
# Check the content type and rename as appropriate
mime = magic.from_file(upload_path, mime=True)
if mime not in ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/tiff', 'image/x-tiff']:
resp = Response('Sorry, but we can only accept jpg, gif, or png files.')
resp.status_code = 400
resp.status_string = '400 Bad Request'
return resp
extension = {'image/jpeg': '.jpg', 'image/pjpeg': '.jpg',
'image/gif': '.gif', 'image/png': '.png',
'image/tiff': '.tiff', 'image/x-tiff': '.tiff'}[mime]
os.rename(upload_path, upload_path + extension)
photo.content_type = mime
return Response('OK')
示例2: error_response
# 需要导入模块: from pyramid.response import Response [as 别名]
# 或者: from pyramid.response.Response import status_string [as 别名]
def error_response(code, msg):
status = {400: '400 Bad Request', 500: '500 Internal Server Error'}[code]
resp = Response(msg)
resp.status_code = code
resp.status_string = status
return resp