Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Protected Pages with Django
#1
Hi everyone .. I wanna make a simple project with Django. I need to safe page project.
For example, if somebody doesn't logging and he/she gets to request a page then return 403 status code.

How I can do that. Thank u for the answer:)
Quote
#2
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):
Quote
#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
Quote

Top Page

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 164 Jun-30-2019, 12:21 AM
Last Post: scidam
  How to handle tables splitted across multiple web pages ankitjindalbti 2 163 Jun-02-2019, 07:33 AM
Last Post: ankitjindalbti
  Scraping external URLs from pages Apook 5 962 Jul-18-2018, 06:42 PM
Last Post: nilamo
  scraping multiple pages of a website. Blue Dog 14 6,895 Jun-21-2018, 09:03 PM
Last Post: Blue Dog

Forum Jump:


Users browsing this thread: 1 Guest(s)