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:
- 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 ...
Get Web Development with Django Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.