这是我的登录视图:
class login(View):
def get(self, request):
c = {}
c.update(csrf(request))
return render_to_response("login.html", c)
def post(self, request):
uname = request.POST["username"]
password = request.POST["password"]
user = authenticate(username=uname, password=password)
if user is None:
c = {}
c.update(csrf(request))
return render_to_response("login.html", c)
else:
auth_login(request, user)
return render(request,"dashboard.html")
这是另一种观点需要登录:
class Index(View):
@method_decorator(login_required)
def get(self, request):
c = {}
c.update(csrf(request))
return render(request,'crm_index.html')
问题是,我使用登录表单登录。我的应用正在渲染dashboard.html。但是当我导航到需要登录的索引时,我被要求再次登录。我无法使用自己的登录页面打开索引。
如果我使用管理站点登录我的应用程序,那么我可以查看索引。
如何在登录视图中登录用户?