I reviewed almost all the examples here and in the documentation, and it just doesn't work at all
So in my settings.py file I have
STATIC_ROOT = '/mattr/static/' STATIC_URL = '/mattr/public/' STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder',) TEMPLATE_CONTEXT_PROCESSORS = ('django.core.context_processors.static',) TEMPLATE_DIRS = ('mattr/public', )
Basically everything you need to process static files.
In urls.py I have the usual page templates (templates just load) and add this extra line
urlpatterns += staticfiles_urlpatterns()
In views.py I have (this is for the main page):
def home(request): t = get_template('index.html'); html = t.render(RequestContext(request)) return HttpResponse(html)
And in the index.html template file, I have a line
<img src="{{ STATIC_URL }}media/images/Mattr1.png">
And yet he never shows images. Even when I try to just go to the image file directly at http://127.0.0.1:8000/mattr/public/media/images/Mattr1.png, it gives me a "Page Error" error. I was a little confused when the path starts, but due to loading the template page, I realized that I have the correct paths.
django django-staticfiles
Jared joke
source share