《Django REST framework 入门到精通》视频课程上线了,全网稀缺资源,深度源码剖析,进阶高手之路!点击链接查看详情


user_image
By  陈镜子先生    On   2019年3月8日 17:46

步骤到这里,登录功能不行了,点击登录,就单纯刷新而已,页面上一直提示那个message消息:请检查填写的内容!。。。。没有跳转到首页,见了鬼了,到底是怎么回事 @csrf_exempt def login(request): if request.session.get('is_login', None): return redirect("/index/") if request.method == "POST": login_form = forms.UserForm(request.POST) message = "请检查填写的内容!" if login_form.is_valid(): username = login_form.cleaned_data['username'] password = login_form.cleaned_data['password'] try: user = User.objects.get(name=username) if user.password == password: request.session['is_login'] = True request.session['user_id'] = user.id request.session['user_name'] = user.name return redirect('/index/') else: message = "密码不正确!" except: message = "用户不存在!" return render(request, 'main/login.html', locals()) login_form = forms.UserForm() return render(request, 'main/login.html', locals()) ----------------------------------------- <form class='form-login' action="/login/" method="post"> {% if message %} <div class="alert alert-warning">{{ message }}</div> {% endif %} {% csrf_token %} <h2 class="text-center">欢迎登录</h2> {# <div class="form-group">#} {# <label for="id_username">用户名:</label>#} {# <input type="text" name='username' class="form-control" id="id_username" placeholder="Username" autofocus required>#} {# </div>#} {# <div class="form-group">#} {# <label for="id_password">密码:</label>#} {# <input type="password" name='password' class="form-control" id="id_password" placeholder="Password" required>#} {# </div>#} <div class="form-group"> {{ login_form.username.label_tag }} {{ login_form.username}} </div> <div class="form-group"> {{ login_form.password.label_tag }} {{ login_form.password }} </div> {# <div class="form-group">#} {# {{ login_form.captcha.errors }}#} {# {{ login_form.captcha.label_tag }}#} {# {{ login_form.captcha }}#} {# </div>#} <button type="reset" class="btn btn-default pull-left">重置</button> <button type="submit" class="btn btn-primary pull-right">提交</button> </form> </div> </div> <!-- /container -->