Django pymysql only connects to the database once. How to operate the database?

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);"
    -sharpexecutemany
    cursor.execute(sql,class_name)
    -sharp
    conn.commit()
    
    conn.close()
    
    cursor.close()
    
    return redirect("../index/")
    
return render(request, "add.html")
< H1 > this is a routine operation, but each time a new function is written, the database is linked < / H1 >
Jul.06,2021

try this

https://github.com/LuciferJack/python-mysql-pool

what I want is a database connection pool that now links the database independently every time a request is made. If you create a database connection pool, then the whole project will only connect to the database once

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3bb66-2c2c1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3bb66-2c2c1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?