File uploads using Ajax has become the de facto standard on the web. People want to see what they have chosen right after selecting a file instead of seeing it after submitting a form. Also, if the form has validation errors, nobody wants to select the files again; the file should still be selected in the form with validation errors.
There is a third-party app, django-ajax-uploader
, that can be used to upload images with Ajax. In this recipe, we will see how to do this.
Let's start with the quotes
app that we created for the Uploading images recipe in Chapter 3, Forms and Views. We will reuse the model and view; however, we'll create a different form and template and add JavaScript too.
Install django-crispy-forms
and django-ajax-uploader
in your local environment using the following commands:
(myproject)$ pip install django-crispy-forms (myproject)$ pip install ajaxuploader
Don't forget to put these apps in INSTALLED_APPS
, as follows:
# conf/base.py or...