tponthieux
tponthieux

Reputation: 1552

web.py development server - favicon.ico - 404 Not Found

When running a web.py application with the development server, how do you get rid of the 404 error for the favicon?

"HTTP/1.1 GET /" - 200 OK
"HTTP/1.1 GET /favicon.ico" - 404 Not Found

Everything I've been able to find about eliminating this error has to do with specifying a path to the resource in your Apache configuration. This obviously doesn't help with the development server use case. Is there a way to specify static resources in the urls tuple? Can you define a document root in the web.py application?

Upvotes: 12

Views: 17791

Answers (4)

xycmu
xycmu

Reputation: 66

The web.py API documentation references a 'web.seeother()' function which generates a
'303 SEE OTHER' response, redirecting a browser to a different location.
(See http://webpy.org/docs/0.3/api#web.application)

This is a server-side solution which doesn't require header changes in html files; particularly useful if the server isn't actually dealing with html files.

Solution:

Map a url route from the default /favicon.ico and create a new class to handle this route:

# Define API Routes
urls = (
    '/', 'index',
    '/favicon.ico', 'icon'
)

Create a (web accessible) static directory containing the favicon.ico

Create a new class to handle this file:

# Process favicon.ico requests
class icon:
    def GET(self): raise web.seeother("/static/favicon.ico")

Here are my server logs showing the requests:

<ip#> - [18/Oct/2013 21:54:54] "HTTP/1.1 GET /favicon.ico" - 303 See Other
<ip#> - [18/Oct/2013 21:54:54] "HTTP/1.1 GET /static/favicon.ico" - 200
<ip#> - [18/Oct/2013 22:03:02] "HTTP/1.1 GET /favicon.ico" - 303 See Other
<ip#> - [18/Oct/2013 22:03:03] "HTTP/1.1 GET /static/favicon.ico" - 304 Not Modified

Upvotes: 5

Anand Chitipothu
Anand Chitipothu

Reputation: 4377

Like Ryan Griggs suggested, but use /static/favicon.ico as href.

<html>
<head>
    <link rel="icon" type="image/png" href="/static/favicon.ico">
    ...

web.py dev server maps all /static/ URLs to files in static/ directory.

Upvotes: 8

vonPetrushev
vonPetrushev

Reputation: 5599

Since web.py limits you to work only with the /static path for your static data, there is not really a way to correctly serve the favicon with the dev server. The best way to get rid of the 404 log is simply to add a url handler in the mapping:

urls = ("/favicon.ico", "dummy")

and in the dummy handler just pass an empty 200 response.

Upvotes: 1

Ryan Griggs
Ryan Griggs

Reputation: 2758

Browsers automatically look for the /favicon.ico file in your website's root directory. This error simply means that the file 'favicon.ico' doesnt't exist. Simply create an icon file (or download one from one of the many favicon creator sites) and place it in your website's root web directory (public_html, etc).

For a better solution, edit your webpages' HTML to include a specific link to a favicon file:

<html>
<head>
    <link rel="icon" type="image/png" href="http://example.com/myicon.png">
    ...

See http://www.w3.org/2005/10/howto-favicon

Upvotes: 2

Related Questions