'method' 对象在 username = (request.POST.get['username']) 中不可下标

时间:2021-04-29 05:09:47

标签: mysql django-views django-forms mysql-connector python-3.9

def signin(request):
    con = mysql.connector.connect(host="localhost",user="root",passwd="",database="pim")
    cursor = con.cursor()
    con2 = mysql.connector.connect(host="localhost",user="root",passwd="",database="pim")
    cursor2 = con2.cursor()
    sqlcommand = "select username from pimapp_employees"
    sqlcommand2 = "select password from pimapp_employees"
    cursor.execute(sqlcommand)
    cursor2.execute(sqlcommand2)
    u=[]
    p=[]
  for i in cursor:
        u.append(i)
    for j in cursor2:
        p.append(j)
    res = list(map(itemgetter(0), u))
    res2 = list(map(itemgetter(0), p))    
    con3 = mysql.connector.connect(host="localhost",user="root",passwd="",database="pim")
    cursor3 = con2.cursor()
    if request.method =="POST":
        username = (request.POST.get['username'])
        password = (request.POST.get['password'])
        k=(len(res))
        i=1
        sqlcommand3 = "select firstname from pimapp_employees where username = username"
        cursor3.execute(sqlcommand3)
        lst =[]
        for firstname in cursor3:
              firstname = firstname
              name2 =''.join(firstname)
        print(name2)
        while( i <k):
            if res[i]==username and res2[i]==password:
               return render(request,'main.html',{'name':name2})
               break
               i++
        else:
            messages.info(request, "Check username or password")
            return redirect('log')

    return render(request,'home.html')   
    return render(request,'main.html')

0 个答案:

没有答案
相关问题