from django.db import connections
def dictfetchall(cursor):
"Return all rows from a cursor as a dict"
columns = [col[0] for col in cursor.description]
return [
dict(zip(columns, row))
for row in cursor.fetchall()
]
def get_list_user():
with connections['example_db'].cursor() as cursor:
cursor.execute("""select * from users """)
connection.close()
row = dictfetchall(cursor)
return row
for x in get_list_user():
print(x['username'])
good luck ...!
Baca artikel lainya: