Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Statefull widgets for django upload
Python JavaScript HTML
branch: master

Merge pull request #3 from fosil/patch-1

Fix django.conf.urls.defaults remove in Django 1.6
latest commit d1eaeb9f0b
@generalov authored


This could help users to resubmit form after validation error was occured without loosing selected files.

Status and License

It is licensed under an Simplified BSD License.


Edit your and append django_resubmit to the INSTALLED_APPS. Also you must specify a resubmit cache backend, for example:

from django_resubmit.settings import *


    'resubmit': {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': '/tmp/resubmit-data',

For more information about cache see Django documentation.


Supply FileFiled with custom FileWidget widget:

from django import forms
from django_resubmit.forms.widgets import FileWidget

class SampleForm(forms.Form):
    name = forms.CharField(max_length=25)
    file = forms.FileField(widget=FileWidget)

Add this url to

url(r'^django_resubmit/', include('django_resubmit.urls', namespace='django_resubmit')),

Advanced settings

There are several advanced settings.


The storage to use. Default:


The size of thumbnails (width, height)



The thumbnailers to use.


        'NAME': 'django_resubmit.thumbnailer.pil_image.Thumbnailer',
        'MIME_TYPES': (
            'image/bmp', 'image/x-ms-bmp',
            'image/png', 'image/jpeg', 'image/gif',
            'image/x-icon', 'image/',)

The built-in thumbnailers are:


The thumbnailer should implement the IThumbnailer interface:

interface IThumbnailer:

    create_thumbnail(size, source): IThumbnail
        Create thumbnail for given Resource

there IThumbnail is:

interface IThumbnail:

    property size : string
        Return thumbnail proposed size

    property mime_type : string
        Return thumbnail MIME type

    property url : string
        Return thumbnail url

    as_file(): file
        Return thumbnail data as file-like object.

How It Works

It stores uploaded file into the temporary storage (cache) on the server with some key and injects this key as hidden field into the form then the ValidationError is occured. When user resubmits the form It restores the file from the cache and puts it into the request.FILES.

It automatically generates and shows thumbnails for uploaded image files. You can easily extend it to show video, flash, etc.

It makes Javascript image preview for just selected (not uploaded) files. Works in Chrome, Firefox and IE.

How To Run Tests

Use tox to run unit tests with different python versions:


Use virtualenv to run example application:

virtualenv python
. ./python/bin/activate
pip install -r requirements.txt
pip install -e .
python example/ test django_resubmit testapp

Bugs and TODO

  • The ability to manage cleaning of orphaned uploads and their thumbnails.
  • Impose restrictions on django-resubmit views to prevent undesirable activity.
  • Improve UI for file uploads (try
  • Write documentation.
  • Commit into the Django.

In order to fix installation of the PIL with ZLIB (PNG/ZIP) support into the tox environments in Ubuntu run the following commands:

sudo ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.a /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib/
Something went wrong with that request. Please try again.