1+.. _favicon:2+3+Adding a favicon4+================5+6+A "favicon" is an icon used by browsers for tabs and bookmarks. This helps7+to distinguish your website and to give it a unique brand.8+9+A common question is how to add a favicon to a flask application. First, of10+course, you need an icon. It should be 16 × 16 pixels and in the ICO file11+format. This is not a requirement but a de-facto standard supported by all12+relevant browsers. Put the icon in your static directory as13+:file:`favicon.ico`.14+15+Now, to get browsers to find your icon, the correct way is to add a link16+tag in your HTML. So, for example:17+18+.. sourcecode:: html+jinja19+20+ <link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">21+22+That's all you need for most browsers, however some really old ones do not23+support this standard. The old de-facto standard is to serve this file,24+with this name, at the website root. If your application is not mounted at25+the root path of the domain you either need to configure the webserver to26+serve the icon at the root or if you can't do that you're out of luck. If27+however your application is the root you can simply route a redirect::28+29+ app.add_url_rule('/favicon.ico',30+ redirect_to=url_for('static', filename='favicon.ico'))31+32+If you want to save the extra redirect request you can also write a view33+using :func:`~flask.send_from_directory`::34+35+ import os36+ from flask import send_from_directory37+38+ @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')42+43+We can leave out the explicit mimetype and it will be guessed, but we may44+as well specify it to avoid the extra guessing, as it will always be the45+same.46+47+The above will serve the icon via your application and if possible it's48+better to configure your dedicated web server to serve it; refer to the49+webserver's documentation.50+51+See also52+--------53+54+* The `Favicon <http://en.wikipedia.org/wiki/Favicon>`_ article on55+ Wikipedia