How to do it...

Let's refine the form for inspirational quotes so that it can support Ajax uploads, using the following steps:

  1. First of all, add the following to your settings:
# or config/ ...UPLOAD_URL = f'{MEDIA_URL}upload/'UPLOAD_ROOT = os.path.join(MEDIA_ROOT, 'upload')
If you want, you can also update the .gitignore file under the MEDIA_ROOT to avoid committing anything to the UPLOAD_ROOT, just by adding /upload/ as a new line.
  1. Then, in the quotes app, we will define a custom file storage system for uploads using the new setting:
# quotes/storages.pyfrom django.conf import settingsfrom import FileSystemStorageupload_storage = FileSystemStorage(location=settings.UPLOAD_ROOT)
  1. Getting ...

Get Django 2 Web Development Cookbook - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.