Uploading images by Ajax
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.
Getting ready
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access