[Django]-Sites_query = connection.execute("SELECT domain FROM django_site") psycopg2 has no attribute execute

4👍

You sould use cursor object to execute query:

cursor = connection.cursor()
sites_query = cursor.execute("SELECT domain FROM django_site")
sites_result = cursor.fetchall()

Don’t forget to close connection after get data:

cursor.close()
connection.close()

Leave a comment