How to serve a static page from urls.py?

1

I have a website in Django where I want to serve favicon.ico - which, being a static file, is in STATIC_URL/caminho/pro/favicon.ico . Is it possible to do this directly from urls.py ? (i.e. without having to write a view just for that)

I found this answer in SOen that says how to map from one standard to another [named], but that is not what I need: I want to map from a pattern to a static URL. Something like:

url(r'^favicon.ico$', view_que_serve_a_partir_do_STATIC_ROOT_ou_redireciona_pro_STATIC_URL),

Is it possible? And if not, what would be the least laborious alternative?

P.S. I'm using Django 1.4.14, in Python 2.6.0 (and no, due to restrictions in my environment you can not upgrade to a newer version ...)

    
asked by anonymous 18.09.2014 / 12:23

1 answer

1

According to an answer to the same question in SOen , this sort of thing is best done in the webserver (Apache, nginx ...) than in Django. However, as a workaround there is the possibility of using a generic view , for example RedirectView :

from django.views.generic.base import RedirectView

class FaviconView(RedirectView):
    url = "/static/favicon.ico"

urlpatterns = patterns('',
    url(r'^favicon.ico$', FaviconView.as_view()),
    
18.09.2014 / 13:43