First, we will override Odoo default favicon custom in this step‑by‑step tutorial. Moreover, we will explain each code block clearly. As a result, you will learn how to inject your own favicon in Odoo 17 or 18. Finally, you will improve your site branding and performance.
Now we will override Odoo default favicon custom by adding a route that serves the custom image.
Create a Custom HTTP Controller
Create controllers/__init__.py:
# controllers/__init__.py
from . import favicon_controller
Then create controllers/favicon_controller.py:
# controllers/favicon_controller.py
import base64
from odoo import http
from odoo.http import request, Response
class FaviconController(http.Controller):
@http.route('/favicon.ico', type='http', auth='user', cors='*')
def serve_custom_favicon(self, **kwargs):
"""Serve the custom favicon or fallback to the default."""
# Get current company record
company = request.env.user.company_id
fab_data = company.custom_fab_icon
if fab_data:
# Decode base64 and return binary
image_data = base64.b64decode(fab_data)
return Response(
image_data,
status=200,
mimetype='image/png'
)
# Fallback: let Odoo default handle it
return request.redirect('/web/static/src/img/favicon.ico')
Explanation:
We import http, request, and Response.
We define /favicon.ico route, which matches default path.
We fetch custom_fab_icon from res.company.
If we find a custom icon, we decode it and return it with mimetype='image/png'.
Otherwise, we redirect to the default favicon.
Define Route and Response
We used auth='user' so only logged‑in users see the favicon. However, you may switch to auth='public' if needed.
Customize QWeb Template for Favicon
Although the controller route overrides /favicon.ico, you may also inject link tags into HTML pages. Create views/assets_template.xml:
However, we recommend using fingerprinted assets in production for better caching.
Test and Verify Custom Favicon
First, go to Settings ▶️ Companies. Then upload a PNG or ICO file in Favicon Settings. After that:
Save your company.
Refresh your browser (Ctrl+F5).
Observe your new icon in the browser tab.
Moreover, open developer tools (F12) to confirm /favicon.ico returns 200 OK with your image.
Performance and Caching Tips
Always optimize your favicon file (PNG 32×32 or ICO).
Moreover, leverage Odoo’s asset bundling by placing your route in web.assets_frontend.
Finally, set proper HTTP headers if you serve static icons frequently.
Troubleshooting and FAQ
Q1: Why does my old favicon still show?
First, clear your browser cache. Next, restart Odoo and refresh with a cache‑buster.
Q2: How do I support multiple file types?
You can detect file extension in your controller:
if fab_data.endswith(';base64'):
# handle ICO or PNG differently
Q3: How can I serve favicon for public users?
Use auth='public' in your route definition.
Conclusion
In conclusion, you learned how to override Odoo default favicon custom by:
Adding a custom field on res.company.
Serving the icon with a custom HTTP controller.
Overriding the QWeb template to load /favicon.ico.
Updating your manifest and init files.
Restarting Odoo and clearing caches.
Now, you can brand your Odoo instance with a unique favicon. Moreover, you can adapt this approach to serve other static assets. If you found this guide helpful, please share it or link back to your blog for best practices.