关键代码:
from pyramid.response import Response
from io import BytesIO
img, strs = create_validate_code()
memstream = BytesIO()
img.save(memstream, "GIF")
request.session['validate'] = strs.lower()
return Response(body=memstream.getvalue(), content_type='image/gif')