5👍
From the docs:
from django.conf.urls.static import static
urlpatterns = patterns("",
# Your stuff goes here
) + static('/', document_root='static/')
There doesn’t appear to be a way to serve a single static file, but at least this helper function is a wrapper which only works when DEBUG = True.
17👍
The easiest way would be to just put it in your static directory with your other static media, then specify its location in your html:
<link rel="shortcut icon" type="image/png" href="{% static 'images/favicon.ico' %}"/>
My old answer was:
You can set up an entry in your urls.py
and just check if debug
is true. This would keep it from being served in production. I think you can just do similar to static media.
if settings.DEBUG:
urlpatterns += patterns('',
(r'^favicon.ico$', 'django.views.static.serve', {'document_root': '/path/to/favicon'}),
)
You also could just serve the favicon from your view.:
from django.http import HttpResponse
def my_image(request):
image_data = open("/home/moneyman/public_html/media/img/favicon.ico", "rb").read()
return HttpResponse(image_data, content_type="image/png")
6👍
This worked for me:
from django.conf.urls.static import static
...
if settings.DEBUG:
urlpatterns += static(r'/favicon.ico', document_root='static/favicon.ico')
- Django get IP only returns 127.0.0.1
- Django – Polymorphic Models or one big Model?
- How to make web framework based on Python like django?
- Django queryset exclude empty foreign key set
- Utility of managed=False option in Django models
0👍
I use this:
from django import conf
from django.conf.urls import static
...
if conf.settings.DEBUG:
urlpatterns += static.static(
r"/favicon.ico", document_root=conf.settings.STATIC_ROOT / "favicon.ico"
)
- Generate unique hashes for django models
- Database table names with Django
- Django Rest Framework using dot in url
- Django: Convert CharField to TextField with data intact
- Cache a django view that has URL parameters
-1👍
Well, you can create your own loader.py file, which loads settings you want to override.
Loading this file should look like this:
try:
execfile(os.path.join(SETTINGS_DIR, 'loader.py'))
except:
pass
and be added at the end of settings.py.
This settings should not be commited into production server, only should appear on development machines. If you are using git, add loader.py into .gitignore.
- How do I exclude South migrations from Pylint?
- How to have a "random" order on a set of objects with paging in Django?
- Adding annotations to all querysets with a custom QuerySet as Manager
- How do I tell Django to save my test database?