Note that there are some explanatory texts on larger screens.

plurals
  1. POCorrect way to serve static user-uploaded files for django-adminfiles
    text
    copied!<p>I am trying to add django-adminfiles to one of my django projects (a zinnia blog).<br> I am using Django 1.3 with the following configuration :</p> <pre><code># setttings.py STATIC_URL = '/static/' STATIC_ROOT = os.path.join(current_dir, 'static_collected') STATICFILES_DIRS = ( '/path/to/myproject/src/django-adminfiles/adminfiles/media', ...) # urls.py urlpatterns += staticfiles_urlpatterns() urlpatterns += patterns('', url(r'^adminfiles/(?P&lt;path&gt;.*)$', 'django.views.static.serve', {'document_root': os.path.join(parent_dir, 'adminfiles')}),) </code></pre> <p>I then run <code>bin/manage collecstatic</code> to collect static files (I am using buildout with djangorecipe).<br> I can then upload files using the admin interface but thumbnails neither appear in the admin interface nor in the public website and I have 404 errors in django's output :</p> <pre><code># If I go to the admin interface at /admin/zinnia/entry/2/ [21/Sep/2011 09:39:16] "GET /adminfiles/all/adminfiles/fluxboxwall_jpg_144x150_q85.jpg HTTP/1.1" 404 1886 [21/Sep/2011 09:39:16] "GET /adminfiles/all/adminfiles/DD_jpg_144x150_q85.jpg HTTP/1.1" 404 1859 # If I visit my public located at /blog [21/Sep/2011 09:36:02] "GET /blog/adminfiles/fluxboxwall.jpg HTTP/1.1" 404 6758 # This file can be accessed through /adminfiles/fluxwall.jpg [21/Sep/2011 09:36:02] "GET /blog/adminfiles/DD.jpg HTTP/1.1" 404 6731 # This file can be accessed through /adminfiles/DD.jpg </code></pre> <p>I can make django-adminfiles work by adding slashes in its templates :</p> <p><a href="https://github.com/carljm/django-adminfiles/blob/master/adminfiles/templates/adminfiles/uploader/base.html#L37" rel="nofollow">templates/adminfiles/uploader.html, line 37</a>, for the thumbnails in the admin interface<br> <code>&lt;li class="item {{f.content_type}} {{f.sub_type}}" {% if f.is_image %}style="background-image:url(</code><strong>/</strong><code>{% thumbnail f.upload 144x150 %});"{% else %}{% if f.mime_image %}style="background-image:url({{ f.mime_image }});"{% endif %}{% endif %}&gt;</code></p> <p><a href="https://github.com/carljm/django-adminfiles/blob/master/adminfiles/templates/adminfiles/render/image/default.html#L2" rel="nofollow">templates/adminfiles/default.html, line 2</a>, to have my pictures displayed in my public blog<br> <code>&lt;img src="</code><strong>/</strong><code>{{ upload.upload.url }}" width="{{ upload.width }}" height="{{ upload.height }}" class="{{ options.class }}" alt="{% if options.alt %}{{ options.alt }}{% else %}{{ upload.title }}{% endif %}" /&gt;</code></p> <p>However, I think I shouldn't have to hack templates to make django-adminfiles work. I have a feeling that something is wrong in my django configuration but I don't know what.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload