Description
How can I serve static files (html, js) easily? Even though I don't need to inject python data, I attempted to do it with jinja and encountered issues.
Additional context
I tried something like:
@router.get("/webui/{file_name}", name="webui.show")
async def webui_show(file_name: str):
template = jinja2.get_template(file_name)
content = template.render()
return HTMLResponse(content=content, status_code=200)
Where jinja2 was
loader = FileSystemLoader(web_dir("dist"))
# no escaping while deubing
jinja2 = Environment(loader=loader, autoescape=False)
But I received an error message "jinja2.exceptions.TemplateSyntaxError: Expected an expression, got 'end of print statement'" when returning JavaScript files. What's sanctioned way to implement simple static file serving in fastapi? If so, it'd be nice to have some documentation around it.
Description
How can I serve static files (html, js) easily? Even though I don't need to inject python data, I attempted to do it with jinja and encountered issues.
Additional context
I tried something like:
Where jinja2 was
But I received an error message "jinja2.exceptions.TemplateSyntaxError: Expected an expression, got 'end of print statement'" when returning JavaScript files. What's sanctioned way to implement simple static file serving in fastapi? If so, it'd be nice to have some documentation around it.