import psycopg2 def djselect(): connection = psycopg2.connect(host='localhost', dbname='FHWDB', user='postgres', password='Q1w2e3r4') cursor = connection.cursor() cursor.execute('''SELECT * FROM public.parse ORDER BY id;''') arr = list(cursor.fetchall()) res = '' k = 0 while k != len(arr): i = arr[k] res = res + f'''