def go_add(request):
if request.method == "POST":
class_name = request.POST.get("cname")
conn=pymysql.connect(host="192.168.2.130",user="root",password="root",database="test",charset="utf8")
cursor=conn.cursor(cursor=pymysql.cursors.DictCursor)
sql="insert into user(user) values(%s);"
#executemany批量提交
cursor.execute(sql,class_name)
#向数据库提交
conn.commit()
conn.close()
cursor.close()
return redirect("../index/")
return render(request, "add.html")
试试这个吧