I know how to set a favicon for a html page. I was wondering if it is possible to set a favicon for all "pages" from my fastapi project? So when I do post and get requests in a browser, a favicon shows. I hope that makes sense?
Thanks, Chris
just return a FileResponse in the get request to '/favicon.ico'
tree
root
|-main.py
|-favicon.ico
main.py
from fastapi import FastAPI
from starlette.responses import FileResponse
app = FastAPI()
favicon_path = 'favicon.ico'
@app.get('/favicon.ico')
async def favicon():
return FileResponse(favicon_path)
/favicon.ico
in that case; you'll need to serve a file under that path if that's what you're looking for (this will assume that your endpoint returns the actual answer to the request). You could add a@router.get('/favicon.ico')
and return a FileResponse in that view: fastapi.tiangolo.com/advanced/custom-response/#fileresponse – MatsLindh