7👍
✅
To restrict views to only logged in users use django’s login required decorator
views.py
from django.contrib.auth.decorators import login_required
@login_required
def index(request):
return render(request, 'professors/index.html')
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index')
]
If they are not logged in they will be redirected to your login page
Source:stackexchange.com