Yes. You can read all about it here: https://docs.djangoproject.com/en/1.8/topics/auth/default/#django.contrib.auth.decorators.login_required … but here are some bullet points:
- add
'django.contrib.auth.middleware.AuthenticationMiddleware'toMIDDLEWARE_CLASSESinsettings.py - add
'django.contrib.auth‘ and'django.contrib.contenttypes'toINSTALLED_APPSinsettings.py - setup a URL for the login using
django.contrib.auth.views.loginfor the view, such asurl(r'^login/$', 'django.contrib.auth.views.login',name="my_login") - In your view, include the login_required decorator and add it before your view. For example…
views.py…
from django.contrib.auth.decorators import login_required
@login_required
def home(request):
return HttpResponse('Home Page')
By default, you then put the template inside my_template_directory/registration/login.html . Further info about that template can be found at the link in the beginning of this post.