Python(3.6.2) Django(2.1.7)
First, import the following modules into view.py of each app
view.py
from django.contrib.auth.mixins import LoginRequiredMixin
Describe as follows in the class related to the display of pages that require login.
view.py
class MypageView(LoginRequiredMixin, generic.ListView):
template_name = 'index.html'
Be sure to specify LoginRequiredMixin in the __first argument __. Otherwise you will not be redirected to the login page.
Specify the redirect destination (login page) when you are not logged in to settings.py.
settings.py
LOGIN_URL = '/accounts/login/'
This completes
Recommended Posts