O'Reilly logo

Web Development with Django Cookbook - Second Edition by Aidas Bendoraitis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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/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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required