Check admin login on my django app
问题 I have created a django app and have linked to the admin index page by modifying base.html. However, the link of the app is accessible directly as well. Can I check on the page or in the views.py of my app if the user is logged in to the django admin or not? 回答1: Use the @staff_member_required decorator: from django.contrib.admin.views.decorators import staff_member_required @staff_member_required def my_view(request): ... 回答2: from django.contrib.auth.decorators import user_passes_test @user