Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Protected Pages with Django
#3
(Feb-12-2019, 06:34 PM)nilamo Wrote: The @login_required decorator: https://docs.djangoproject.com/en/2.1/to...n_required
Quote:
from django.contrib.auth.decorators import login_required @login_required def my_view(request):
Or, if you want to check for certain group membership (so only some members can get in, instead of just anyone logged in), you can use @user_passes_test https://docs.djangoproject.com/en/2.1/to...ass-a-test
Quote:
from django.contrib.auth.decorators import user_passes_test def email_check(user): return user.email.endswith('@example.com') @user_passes_test(email_check) def my_view(request):



thank you
Reply


Messages In This Thread
Protected Pages with Django - by xxp2 - Feb-12-2019, 05:54 PM
RE: Protected Pages with Django - by nilamo - Feb-12-2019, 06:34 PM
RE: Protected Pages with Django - by xxp2 - Feb-12-2019, 07:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,326 Jun-30-2019, 12:21 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020