Log function and database validation:

Import the render django.shortcuts from, the HttpResponse, the redirect 
Import pymysql

# here Wallpaper the Create your views.

DEF index (Request):
Print (request.path_info)
return the HttpResponse ( '<h1 of> index </ h1 of>')
# return the render (Request, 'index.html')

DEF Modal (request):
return the render (request, 'modal.html')

DEF the Login (request):
# determine if a get request to return the login page:
IF request.method == "GET":
return the render (request, "login.html")
# otherwise handle post requests, submit the data acquisition:
the else:
Print (request.POST)
# obtain a user name:
username = request.POST.get ( "the user")
password = request.POST .get ( "password")
# Username and password verification:
conn = pymysql.connect ( user="root", password="123", db="alex", charset="utf8" )
cursor = conn.cursor ()
ret = cursor.execute ( "select * from user where username = %s and password = %s",(username,password))
if ret:
#登录成功:
return redirect("/index/")
else:
return render(request,"login.html",{"error":"用户名或密码错误"})

Guess you like

Origin www.cnblogs.com/zhang-da/p/12031833.html