9-5,4分半,测试有无该用户,报错进不去login页面
来源:9-5 dashboard搭建与管理员模块开发(5)
weixin_慕斯卡7041133
2020-04-16

写回答
2回答
-
deweizhang
2020-04-17
你的错误已经告诉你了 他说不能返回一个httpresopne对象 用了none替代 你在哪一行打印一个print 看看是哪一行报错 然后把对应行的信息试着打印一下就知道了 值传的有问题
00 -
weixin_慕斯卡7041133
提问者
2020-04-16
这是auth.py
# coding:utf-8 from django.views.generic import View from django.shortcuts import redirect,reverse from django.contrib.auth import login,authenticate from django.contrib.auth.models import User from app.libs.base_render import render_to_response class Login(View): TEMPLATE = 'dashboard/auth/login.html' def get(self,request): data={'error':''} return render_to_response(request,self.TEMPLATE,data=data) def post(self,request): username = request.POST.get('username') password = request.POST.get('password') data={} exists = User.objects.filter(username=username).exists() if not exists: data['error'] = 'no this user' return render_to_response(request,self.TEMPLATE,data=data) user = authenticate(username=username,password=password) if not user: data['error']='wrang password' return render_to_response(request,self.TEMPLATE,data=data) if not user.is_superuser: data['error']='你无权登录' return render_to_response(request,self.TEMPLATE,data=data) login(request,user) return redirect(reverse('dashboard_index'))这是login.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>登录</title> <link href="/static/dashboard/css/bootstrap.min.css" rel="stylesheet" /> <link href="/static/dashboard/css/login.css" rel="stylesheet" /> </head> <body> <form action="/dashboard/login" method="POST"> ${csrf_token} <div class="edit-area"> <div class="form-group "> <input type="text" name="username" class="form-control" placeholder="用户名"> </div> <div class="form-group"> <input type="password" name="password" class="form-control" placeholder="密码"> </div> <button type="submit" class="btn btn-default">登录</button>${error} </div>> </form> </body> </html>00
相似问题