django를 통해 mysql 데이터를 업데이트하는 방법은 무엇입니까? 어떤 오류도 발생하지 않습니다. 내 코드에서 어디에 문제가django를 사용하여 mysql 데이터를 업데이트하는 방법은 무엇입니까?
views.py
def update_db_data(request):
conn = MySQLdb.connect(host= "localhost", user="test_user", passwd="test_pwd",db="myproject")
cursor = conn.cursor()
try:
cursor.execute("UPDATE user SET user_name = 'test'")
print("sucess")
html = "<html><body>sucess</body></html>"
conn.commit()
except:
print("fail")
html = "<html><body>fail</body></html>"
conn.rollback()
conn.close()
return HttpResponse(html)
을 가르쳐주세요. 상태 업데이트를 수행하는 방법은 무엇입니까?
eg:- UPDATE user SET user_name = 'test' where id =2;
Django-ORM은이 간단한 쿼리를 사용합니다. 왜 그것을 사용하지 않습니까? –