Django-file-form helps you to write forms with a pretty ajax upload
Project description
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.8 - 1.10.
Note that version 0.1.7 also supports Django 1.7.
Usage
1 Install django-file-form
pip install django-file-form
2 Add the apps to your INSTALLED_APPS
You must include ‘django_file_form’ and ‘django_file_form.ajaxuploader’
INSTALLED_APPS = [
'django_file_form',
'django_file_form.ajaxuploader',
]
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 javascript and css in your template
<script src="{% static "ajaxuploader/js/fileuploader.js" %}"></script>
<script src="{% static "file_form/file_form.js" %}"></script>
<link rel="stylesheet" href="{% static "ajaxuploader/css/fileuploader.css" %}">
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 Include the upload_template.html in your template
{% include 'django_file_form/upload_template.html' %}
9 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)
10 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']
form.delete_temporary_files()
return super(ExampleFormView, self).form_valid(form)
Also see the testproject in the repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for django_file_form-0.2.0-py2.7.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | a817f136d997dedf9304a0ff90688616d7bab04fbe0bbf98d1fed501805f7a5a |
|
MD5 | 4857470dad0dc69a5dcbc39332c00ff3 |
|
BLAKE2b-256 | 94af47a2cac7510788d341bcbbc15bfcec5b21edd4db18cc6d03f4561559fcf1 |
Hashes for django_file_form-0.2.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae5fa31723f148f9017c4b1113172700f9e35f6b6adc8172eb21c834f1616b17 |
|
MD5 | cadb8d406d215350f706087ad6827e4a |
|
BLAKE2b-256 | 50bfdfe861e303eb59a25ed1e94a38e757dc4f0d78d3e20a495ca5ccaa10b95c |