Skip to content

Instantly share code, notes, and snippets.

@Kotauror
Last active October 29, 2018 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kotauror/e121bbf170c61d34c70fffbd7f135b41 to your computer and use it in GitHub Desktop.
Save Kotauror/e121bbf170c61d34c70fffbd7f135b41 to your computer and use it in GitHub Desktop.
psql1.py
from flask import Flask
import time
import os
from models import db
from flask_sqlalchemy import SQLAlchemy
from models import Contact
app = Flask(__name__)
POSTGRES = {
'user': 'myUserName',
'pw': 'myPassword',
'db': 'myDBName',
'host': 'endPoint',
'port': '5432',
}
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://%(user)s:\
%(pw)s@%(host)s:%(port)s/%(db)s' % POSTGRES
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
@app.route('/')
def hello_world():
contacts = Contact.query.all()
return "We have " + str(len(contacts)) + " in the db and the contact names are: " + contacts[0].name + " and " + contacts[1].name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment