Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to know connected user in django

#First make sure you have SessionMiddleware and AuthenticationMiddleware middlewares added to your MIDDLEWARE_CLASSES setting.

#The current user is in request object, you can get it by:

def sample_view(request):
    current_user = request.user
    print current_user.id
Comment

django check if user is admin

{% if user.is_superuser %}
    <p>Hello, admin.</p>
{% else %}
    <p>Hello, ordinary visitor.</p>
{% endif %}
Comment

check anonim user django

request.user.is_anonymous
Comment

django check user admin

user.is_superuser
Comment

check auth user django

from django.conf import settings
from django.shortcuts import redirect

def my_view(request):
    if not request.user.is_authenticated:
        return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path))
    # ...
Comment

PREVIOUS NEXT
Code Example
Python :: how to use cv2.COLOR_BGR2GRAY 
Python :: python custom sort 
Python :: cross join pandas 
Python :: pyplot new figure 
Python :: pandas dict from row 
Python :: python how to remove item from list 
Python :: python if any element in string 
Python :: python email 
Python :: while loop python 
Python :: get required packages from python project 
Python :: args kwargs python 
Python :: import file from parent directory python 
Python :: python dictionary get 
Python :: intersection() Function of sets in python 
Python :: flask debugtoolbar 
Python :: django pandas queryset 
Python :: sum first 100 integers in python 
Python :: how to put a image in flask 
Python :: showing specific columns pandas 
Python :: tkinter disable button styles 
Python :: how to run django in jupyter 
Python :: pandas unique values to list 
Python :: is string mutable in python 
Python :: displaying cv2.imshow on specific window position 
Python :: if main 
Python :: django include 
Python :: create pandas dataframe from dictionary 
Python :: python sort dictionary by value 
Python :: jupyter tabnine for jupyter notebook 
Python :: python thousands separators 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =