Downloading authorized files

Sometimes, you might need to allow only specific people to download intellectual property from your website. For example, music, videos, literature, or other artistic works should be accessible only to the paid members. In this recipe, you will learn how to restrict image downloads only to the authenticated users using the contributed Django auth app.

Getting ready

To start, create the quotes app as in the Uploading images recipe.

How to do it…

Execute these steps one by one:

  1. Create the view that will require authentication to download a file, as follows:
    # quotes/ # -*- coding: UTF-8 -*- from __future__ import unicode_literals import os from django.shortcuts import get_object_or_404 from django.http import FileResponse ...

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

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