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
  delete pages in pdf according to bookmarks vagser 0 255 Sep-29-2018, 11:33 AM
Last Post: vagser
  Scraping external URLs from pages Apook 5 668 Jul-18-2018, 06:42 PM
Last Post: nilamo
  Download entire web pages and save them as html file with urllib.request fyec 2 527 Jul-13-2018, 10:12 AM
Last Post: Larz60+
  Duplicate Pages in a PDF wrotenberry 10 2,232 May-04-2018, 05:16 PM
Last Post: wrotenberry
  Reading data from password protected excel Anirudh_Avantsa 2 3,750 Apr-04-2018, 03:26 PM
Last Post: nilamo
  Program that outputs HQ addresses of companies from Google + Local pages frenchgirl1309 2 1,426 Nov-14-2016, 10:11 PM
Last Post: Ofnuts

Forum Jump:


Users browsing this thread: 1 Guest(s)