django and favicon.ico problem

410 views
Skip to first unread message

architecture

unread,
Dec 16, 2008, 5:45:27 AM12/16/08
to Django users
i was working with php and always i put the favicon.ico in the root of
the website but now the problem with django occurs
now i'm working with django and i have a problem now
i used
1. static.serve
2. .htaccess
3.redirect_to

but none of them works have you any idea for using favicon.ico in the
website

please help

Graham Dumpleton

unread,
Dec 16, 2008, 5:50:57 AM12/16/08
to Django users
How are you hosting Django? Are you using mod_python, mod_wsgi or
fastcgi? What you use dictates what you need to do.

Graham

Malcolm Tredinnick

unread,
Dec 16, 2008, 8:04:35 PM12/16/08
to django...@googlegroups.com

There's nothing Django or PHP-specific about setting this up. However,
if you've configured your Django installation to control everything
under "/", then you'll need to make sure it also responds to request for
favico.

An even easier solution is simply to put the favicon file wherever you
serve other static data from (e.g. where your stylesheets and images
are) and put a <link rel="icon"...> line in your base template to point
clients to the right location.

Regards,
Malcolm


Peter Herndon

unread,
Dec 17, 2008, 8:55:21 AM12/17/08
to django...@googlegroups.com
I've done favicons as per Malcolm's suggestion, with a link in my base
template to e.g. /media/images/favicon.ico, and that works
satisfactorily for most cases. The favicon shows as expected in
browser address bars, etc.

However, since favicons arose via convention, where the convention was
to place them in the root of the server, some old and/or stupid UAs
still request them at /, rather than following the link. Which means
I've received 404 emails.

I haven't bothered to try fixing it yet, but I wonder if a redirect
from /favicon.ico to /media/images/favicon.ico might solve that issue.
If I get a chance I'll test it today, see if works. Has anyone else
experimented with this?

---Peter

3lancer.eu

unread,
Dec 17, 2008, 12:31:53 PM12/17/08
to Django users
HI,

> I haven't bothered to try fixing it yet, but I wonder if a redirect
> from /favicon.ico to /media/images/favicon.ico might solve that issue.
>  If I get a chance I'll test it today, see if works.  Has anyone else
> experimented with this?

Well, at least a couple of ways to fix that. If you're hosting your
project with Apache, I suggest trying a .htaccess / httpd.conf
solution with mod_rewrite. If that's not what you like, you can add
favicon.ico to your django urlconf and code a simple view that will
serve .ico data with proper content-type as mentioned for example in
the Django Book: http://www.djangobook.com/en/1.0/chapter11/. Of
course you can also code a HTTP 301 redirect there using django, but
doing rewrite at server level will save you some time and resources.

HTH.

Regards,
Piotr

felix

unread,
Dec 17, 2008, 6:12:09 PM12/17/08
to django...@googlegroups.com

you can put it directly in your http-vhosts.conf file

<VirtualHost *:80>
             ServerName crucial-systems.com
             DocumentRoot /home/crucial/crucial-stack/crucialwww
... etc...

Alias /favicon.ico "/home/crucial/crucial-stack/crucialwww/favicon.ico"

...

WSGIScriptAlias / /home/crucial/crucial-stack/crucial/crucial.wsgi



note that even though the document root appears to be mapped to the crucialwww directory, in practice the WSGIScriptAlias / means that everything is directed to django.

all image and css directories I also use Alias (before the WSGIScriptAlias) to map those to the correct directories.

I used to do a lot of symlinks and juggling of my directories.  I'm preferring this method now as its much easier to change and move things.


-fx

Graham Dumpleton

unread,
Dec 17, 2008, 6:23:23 PM12/17/08
to Django users


On Dec 18, 10:12 am, felix <crucialfe...@gmail.com> wrote:
> you can put it directly in your http-vhosts.conf file
>
> <VirtualHost *:80>
>              ServerName crucial-systems.com
>              DocumentRoot /home/crucial/crucial-stack/crucialwww
> ... etc...
>
> Alias /favicon.ico "/home/crucial/crucial-stack/crucialwww/favicon.ico"
>
> ...
>
> WSGIScriptAlias / /home/crucial/crucial-stack/crucial/crucial.wsgi
>
> note that even though the document root appears to be mapped to the
> crucialwww directory, in practice the WSGIScriptAlias / means that
> everything is directed to django.
>
> all image and css directories I also use Alias (before the WSGIScriptAlias)
> to map those to the correct directories.
>
> I used to do a lot of symlinks and juggling of my directories.  I'm
> preferring this method now as its much easier to change and move things.

As documented for mod_wsgi in:

http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#Hosting_Of_Static_Files

This is why I asked how Django instance was originally being hosted.

FWIW, if using mod_python you can from memory still use Alias, but
also need to specify a Location directive for that URL path and
SetHandler to None. If you don't have the latter bit the request still
gets sucked into mod_python rather than being served as a static file.
YMMV vary on getting this to work though because mod_python doesn't
interleave properly with file based resource directives such as Alias
where as mod_wsgi does.

Graham

> -fx
Reply all
Reply to author
Forward
0 new messages