From ace73dd9766596b2725158d43c12df4d01a43470 Mon Sep 17 00:00:00 2001 From: ElLorans Date: Sun, 3 Nov 2024 21:46:43 +0100 Subject: [PATCH 1/2] docs: adding a favicon --- doc/advanced.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/advanced.rst b/doc/advanced.rst index b938006ea..41da18f66 100644 --- a/doc/advanced.rst +++ b/doc/advanced.rst @@ -626,3 +626,13 @@ This targets SQLAlchemy specifically. Unlike the previous setting, this will specifically only affect the behaviour of IntegrityErrors. These usually come from violations on constraints in the database, for example trying to insert a row with a primary key that already exists. + +Adding a favicon to the admin page +************************************ +Adding a favicon to flask-admin is easy: just save a .ico file and add a /favicon.ico +route to your flask app. + + from flask import redirect, url_for + @app.route("/favicon.ico") + def favicon(): + return redirect(url_for("static", filename="favicon.ico")) From c7c1aac0ba59a674e0f74e3f7bbf2bc5346b1331 Mon Sep 17 00:00:00 2001 From: ElLorans Date: Sun, 3 Nov 2024 21:54:08 +0100 Subject: [PATCH 2/2] use redirect in place of send_file --- examples/sqla/admin/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/sqla/admin/main.py b/examples/sqla/admin/main.py index d8a6a6300..5c6fb1a24 100644 --- a/examples/sqla/admin/main.py +++ b/examples/sqla/admin/main.py @@ -1,5 +1,6 @@ import flask_admin as admin -from flask import send_file +from flask import redirect +from flask import url_for from flask_admin.babel import gettext from flask_admin.base import MenuLink from flask_admin.contrib import sqla @@ -42,7 +43,7 @@ def index(): @app.route("/favicon.ico") def favicon(): - return send_file("static/favicon.ico") + return redirect(url_for("static", filename="/favicon.ico")) # Custom filter class