I'm running a django 1.4.1 app.
I didn't realize that just including django.contrib.staticfiles
into INSTALLED_APPS
in your settings is enough to get static files served while settings.DEBUG
is True, i.e., you don't have to manually add anything to your urls file.
I also noticed that this bypasses the django middleware. Does anyone know how or why this happens?
I just created a blank new project, my views.py:
from django.http import HttpResponse
def index(request):
html = '<html><body>Logo: <img src="/static/logo.gif"></body></html>'
return HttpResponse(html)
My urls.py:
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^$', 'testapp.views.index', name='home'),
)
My settings.py has specified a directory to look for static files, and it also has this added:
MIDDLEWARE_CLASSES = (
'testapp.middleware.TestMiddleware',
...
)
Using this middleware:
from __future__ import print_function
class TestMiddleware(object):
def process_request(self, request):
print("[REQUEST]", request.path)
And when I make a request, this gets printed out:
[REQUEST] /
[18/Jan/2013 15:30:27] "GET / HTTP/1.1" 200 60
[18/Jan/2013 15:30:27] "GET /static/logo.gif HTTP/1.1" 200 2190
[REQUEST] /favicon.ico
Is it something to do with how the test server starts up?