switch to BytesIO for template rendering