django-file-form 0.1.5

Django-file-form helps you to write forms with a pretty ajax upload

Django file form

Django-file-form helps you to write forms with a pretty ajax upload.

Features:

  • You can easily add an ajax file-upload to a form.
  • The ajax upload works the same as an html upload.
    • This means that you don't have to change your code to support ajax upload.
  • Supports single and multiple file upload.

The project is hosted on github.

Works with Django 1.4-1.7.

Usage

1 Install django-file-form

pip install django-file-form

2 Include the app in your settings

INSTALLED_APPS = [
    …
    'django_file_form'
]

3 Add the app to your urls

In this example we use the url upload/. You can use a different url if you like.

urlpatterns = patterns(
    '',
    url(r'^upload/', include('django_file_form.urls')),
)

4 Add FileFormMixin to your form

from django_file_form.forms import FileFormMixin

class ExampleForm(FileFormMixin, forms.Form):
    pass

5 Add a UploadedFileField

from django_file_form.forms import FileFormMixin, UploadedFileField

class ExampleForm(FileFormMixin, forms.Form):
    input_file = UploadedFileField()

6 Include fileuploader.js and file_form.js in your template

<script src="{{ STATIC_URL }}ajaxuploader/js/fileuploader.js"></script>
<script src="{{ STATIC_URL }}file_form/file_form.js"></script>
<link rel="stylesheet" href="{{ STATIC_URL }}ajaxuploader/css/fileuploader.css">

By the way, you must also include jquery.

7 Call the initUploadFields javascript function

<form id="example-form" method="POST" enctype="multipart/form-data">
   {% csrf_token %}
   {{ form }}
</form>

<script>
   $(function() {
       initUploadFields($('#example-form'));
   });
</script>

8 Handle uploaded files

class ExampleFormView(generic.FormView):
    template_name = 'example_form.html'
    form_class = forms.ExampleForm

    def form_valid(self, form):
        input_file = form.cleaned_data['input_file']

        return super(ExampleFormView, self).form_valid(form)

9 Delete temporary files

class ExampleFormView(generic.FormView):
    template_name = 'example_form.html'
    form_class = forms.ExampleForm

    def form_valid(self, form):
        input_file = form.cleaned_data['input_file']

        self.delete_temporary_files()

        return super(ExampleFormView, self).form_valid(form)

Also see the testproject in the repository.

Apache License, Version 2.0

Author

Marco Braak

Pip

django-file-form==0.1.5

Classifiers

  • Programming Language :: Python :: Implementation :: PyPy
  • Programming Language :: Python :: Implementation :: CPython
  • Programming Language :: Python :: 3.4
  • Programming Language :: Python :: 3.3
  • Programming Language :: Python :: 2.7
  • Programming Language :: Python :: 2.6
  • License :: OSI Approved :: Apache Software License
  • Intended Audience :: Developers
  • Framework :: Django
  • Development Status :: 5 - Production/Stable
File Type Python Version Uploaded On Downloads
django_file_form-0.1.5-py2.7.egg Egg 2.7 Sept. 9, 2014 370
django_file_form-0.1.5-py2-none-any.whl Wheel 2.7 Sept. 9, 2014 351
django-file-form-0.1.5.tar.gz Source Sept. 9, 2014 397
Version Release Date
0.1.5 Sept. 9, 2014
0.1.4.5 Oct. 10, 2013
0.1.4.4 Sept. 23, 2013
0.1.4.3 Sept. 23, 2013
0.1.4 May 24, 2013
0.1.3 Nov. 4, 2014
Date Package Version Action
Nov. 4, 2014, 1:12 p.m. django-file-form 0.1.5 Release Created
Nov. 4, 2014, 1:12 p.m. django-file-form 0.1.4 Release Created
Nov. 4, 2014, 1:12 p.m. django-file-form 0.1.3 Release Created
Nov. 4, 2014, 1:12 p.m. django-file-form 0.1.4.5 Release Created
Nov. 4, 2014, 1:12 p.m. django-file-form 0.1.4.4 Release Created
Nov. 4, 2014, 1:12 p.m. django-file-form 0.1.4.3 Release Created
Nov. 4, 2014, 1:12 p.m. django-file-form Package Created