Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 295
tponthieux Avatar asked Jul 24 '12 16:07

tponthieux


3 Answers

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
like image 102
xycmu Avatar answered Nov 16 '22 15:11

xycmu


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.

like image 40
Anand Chitipothu Avatar answered Nov 16 '22 16:11

Anand Chitipothu


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

like image 2
Ryan Griggs Avatar answered Nov 16 '22 16:11

Ryan Griggs