Skip to content

Instantly share code, notes, and snippets.

@nezuppo
Created January 25, 2022 12:57
Show Gist options
  • Save nezuppo/c36bbb4c1f81da348ba74e8ccf3001bf to your computer and use it in GitHub Desktop.
Save nezuppo/c36bbb4c1f81da348ba74e8ccf3001bf to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import psycopg2
from flask import (
Flask,
Response,
)
DATABASE_URL = os.environ.get('DATABASE_URL')
app = Flask(__name__)
@app.route('/')
def root():
with psycopg2.connect(DATABASE_URL) as conn:
with conn.cursor() as curs:
curs.execute('SELECT * FROM testtable')
result = curs.fetchall()
return Response(result[0][0])
if __name__ == '__main__':
app.run()
web: gunicorn app:app --log-file=-
gunicorn==20.1.0
Flask==2.0.2
psycopg2==2.9.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment