I have the following Hello world code for my Heroku app. Also in my project's root folder, I have a favicon.ico.

import os
from flask import Flask
app = Flask(__name__)

html = '''
<!doctype html>
    <link rel="shortcut icon" href="/favicon.ico">
    <title>Hello world!</title>
    <p>Hello world!</p>

def index():
    return html

if __name__ == '__main__':
    port = int(os.environ.get('PORT', 5000))
    app.run(host='', port=port)

When I browse to my app, I don't see a favicon. Also, when I check heroku logs, I get the following 404 line:

2012-02-14T05:23:29+00:00 app[web.1]: <ip.ad.dr.es> - - [14/Feb/2012 05:23:29] "GET /favicon.ico HTTP/1.1" 404 -

3 Answers 3


I just found it right here: http://flask.pocoo.org/docs/patterns/favicon/

I varied from it a bit and here's what I did:

  1. In my tree, I store the icon as static/images/favicon.ico
  2. In the HTML, I have the following line in the <head>:

    <link rel="shortcut icon" href="/favicon.ico">
  3. In my Flask app, I have the following URL handler for /favicon.ico

    def favicon():
        return send_from_directory(os.path.join(app.root_path, 'static', 'images'),
                                   'favicon.ico', mimetype='image/png')

    Why image/png? Because if I use image/vnd.microsoft.icon, then I browse to http://myapp.heroku.com/favicon.ico, I get a download dialog box. image/png just displays the favicon on the page (at least on Chrome).


I put my favicon.ico image in my public/ folder in my rails app. Then I deployed to heroku and had to clear my browser cache before the new one showed up.


Here is what I use:

<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">

I believe the "shortcut" should be in there for Internet Explorer (although IE will usually check for a favicon regardless).

However, it sounds like the icon is in the wrong location. You should be able to access it via yoursite.com/favicon.ico. You could also check by viewing the page source in Google Chrome and /favicon.ico will be an underlined link - click that to open the location you have specified.

UPDATE: Do you have a .htaccess file? From what you have said, it sounds like you need to make an exception for existing files to bypass the app. If you are using Apache you'd use something like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule your_rule_here [L]

There should be an equivalent for the platform you are using.

  • Is this on Flask? I think Flask looks for a handler script for every URL GET sent to it. I still get 404's.
    – Kit
    Feb 15, 2012 at 0:33
  • @Kit Sorry, to be honest I don't know anything about Heroku or Flask. I just assumed the app worked fine but outputted some incorrect HTML. Feb 15, 2012 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.