I see we can use html, file, file_streaming and some other to respond appropriately.
I am currently using app.static to serve other file including css, js.
How can i create a response for css, js files without app.static?
For the time being, I am doing this
from sanic import HTTPResponse
async def css(body, headers=None):
content_type: str = "text/css; charset=utf-8"
return HTTPResponse(body, headers=headers, content_type=content_type)
async def serve_css(_):
css_file = await open(f'./static/css/{css_file_name}')
content = await css_file.read()
await css_file.close()
return await css(content)
This is a cut down version of my code. I believe this is not available as builtin.