Authentication in Django View Django.How

Author avatar wrote on 06/06/2022

Login required Function based

from django.contrib.auth.decorators import login_required

@login_required
def pricechecker(request):

Login required View based

from django.utils.decorators import method_decorator

@method_decorator(login_required, name='dispatch')
class UserDashboard(Account):

 

If registered user

if request.user.is_authenticated:

 

Do something for authenticated users.
If owner

profile.user = request.user

 

Based in user type

user_type = request.user.profile.user_type
if user_type == 'AD':

 

Do something

 

CRUDgen Django CRUD generator