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.
Execute these steps one by one:
Create the view that will require authentication to download a file, as follows:
# quotes/views.py # -*- coding: UTF-8 -*- from __future__ import unicode_literals import os from django.shortcuts import get_object_or_404 from django.http import FileResponse from django.utils.text import slugify from django.contrib.auth.decorators import login_required from .models import InspirationalQuote @login_required(login_url="my_login_page") def download_quote_picture(request, quote_id): quote = get_object_or_404...