Quantcast
Channel: User spraff - Stack Overflow
Viewing all articles
Browse latest Browse all 55

Django serve static files e.g. favicon.ico without `{% load static %}`

$
0
0

I have successfully followed the popular solution for serving static files in Django:

  • I have /myproject/myapp/static/favicon.ico
  • I use <link rel="icon" href="{%static 'favicon.ico' %}" /> in my html template

But if I omit the <link rel...> from html then the browser will by default try to GET /favicon.ico which predictably logs

Not Found: /favicon.ico

How can I tell Django "if anything in urlpatterns does not match the GET string, and that GET string matches a file within a certain directory, just serve that file"?

(Then I would be able to write e.g. <script src="/script.js"> and have /myproject/myapp/static-or-wherever/script.js be served without using {% use static %} in a template -- e.g. if I browse to http://my-site.com/script.js manually.)


Viewing all articles
Browse latest Browse all 55

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>