Skip to content
Myr

Pattern documentation for favicons

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Dag Odenhall · committed by Armin Ronacher · parent 99be2ec · Browse files · 2 files+56 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>

Diff stats

2 files+56 added−0 removed

  • other:+56 added−0 removed

2 files+56 added−0 removed

added:docs/patterns/favicon.rst+55 added
1.. _favicon:23Adding a favicon4================56A "favicon" is an icon used by browsers for tabs and bookmarks. This helps7to distinguish your website and to give it a unique brand.89A common question is how to add a favicon to a flask application. First, of10course, you need an icon. It should be 16 × 16 pixels and in the ICO file11format. This is not a requirement but a de-facto standard supported by all12relevant browsers. Put the icon in your static directory as13:file:`favicon.ico`.1415Now, to get browsers to find your icon, the correct way is to add a link16tag in your HTML. So, for example:1718.. sourcecode:: html+jinja1920 <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">2122That's all you need for most browsers, however some really old ones do not23support this standard. The old de-facto standard is to serve this file,24with this name, at the website root. If your application is not mounted at25the root path of the domain you either need to configure the webserver to26serve the icon at the root or if you can't do that you're out of luck. If27however your application is the root you can simply route a redirect::2829 app.add_url_rule('/favicon.ico',30 redirect_to=url_for('static', filename='favicon.ico'))3132If you want to save the extra redirect request you can also write a view33using :func:`~flask.send_from_directory`::3435 import os36 from flask import send_from_directory3738 @app.route('/favicon.ico')39 def favicon():40 return send_from_directory(os.path.join(app.root_path, 'static'),41 'favicon.ico', mimetype='image/vnd.microsoft.icon')4243We can leave out the explicit mimetype and it will be guessed, but we may44as well specify it to avoid the extra guessing, as it will always be the45same.4647The above will serve the icon via your application and if possible it's48better to configure your dedicated web server to serve it; refer to the49webserver's documentation.5051See also52--------5354* The `Favicon <http://en.wikipedia.org/wiki/Favicon>`_ article on55 Wikipedia
modified:docs/patterns/index.rst+1 added
30 unmodified lines
31 jquery32 errorpages33 lazyloading34 mongokit35 favicon