Restricting access to the connected members

When developers implement an authentication system, it's usually to limit access to anonymous users. In this section, we'll see two ways to control access to our web pages.

Restricting access to views

The authentication module provides simple ways to prevent anonymous users from accessing some pages. Indeed, there is a very convenient decorator to restrict access to a view. This decorator is called login_required.

In the example that follows, we will use the designer to limit access to the page() view from the create_developer module in the following manner:

  1. First, we must import the decorator with the following line:
    from django.contrib.auth.decorators import login_required
  2. Then, we will add the decorator ...

Get Django: Web Development with Python 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.