zoukankan      html  css  js  c++  java
  • Django登录验证——原生表单验证

    直接上代码,

    In views.py

     1 from django.shortcuts import render,redirect
     2 from django.contrib.auth import authenticate
     3 from django.http import HttpResponse
     4 
     5 def login(request):
     6     context={}
     7     if request.method=='GET':
     8         return render(request,'login.html',context)
     9     else:
    10         username=request.POST.get('username')
    11         password=request.POST.get('password')
    #Account为用户自定义表单
    12 user = Account.objects.filter(username__exact=username,password__exact=password)
    13
    if user.exists(): 14 return redirect(to='post') 15 else: 16 return HttpResponse("Login failed,please go back to try it again")

    验证失败的话,不能很好的提示,估计这是官方不推荐该方式的理由之一吧

  • 相关阅读:
    2. 两数相加
    1. 两数之和
    x-pack elasticsearch
    简单的文档
    PHP imagepng函数 问题
    Nginx 配置
    nginx内置变量
    TCP通信
    mysql 的一些操作
    ubuntu 软件包降级
  • 原文地址:https://www.cnblogs.com/reaptem/p/7288451.html
Copyright © 2011-2022 走看看