python - Setting up postgres with flask on win7 -


enter image description here

i working on flask app based on http://code.tutsplus.com/tutorials/intro-to-flask-signing-in-and-out--net-29982.

as part of tut i'm trying connect postgres server, structure in screenshot. i've added table 'yournewdb' can see.

based on tut have following code in main file ('routes.py'):

app.config['sqlalchemy_database_uri'] = "postgresql://postgres:123@localhost/yournewdb"  models import db db.init_app(app)  @app.route('/testdb') def testdb():   if db.session.query("1").from_statement("select 1").all():     return 'it works.'   else:     return 'something broken.' 

models.py:

from flask.ext.sqlalchemy import sqlalchemy werkzeug import generate_password_hash, check_password_hash  db = sqlalchemy()  class user(db.model):   __tablename__ = 'users'   uid = db.column(db.integer, primary_key = true)   firstname = db.column(db.string(100))   lastname = db.column(db.string(100))   email = db.column(db.string(120), unique=true)   pwdhash = db.column(db.string(54))    def __init__(self, firstname, lastname, email, password):     self.firstname = firstname.title()     self.lastname = lastname.title()     self.email = email.lower()     self.set_password(password)    def set_password(self, password):     self.pwdhash = generate_password_hash(password)    def check_password(self, password):     return check_password_hash(self.pwdhash, password) 

when go http://127.0.0.1:5000/testdb i'm getting internal server error. debugger gives:

c:\envs\virtalenvs\flask_mini\lib\site-packages\flask_sqlalchemy\__init__.py:800: userwarning: sqlalchemy_track_modifications adds significant overhead , disabled default in future.  set true suppress warning.   warnings.warn('sqlalchemy_track_modifications adds significant overhead , disabled default in future.  set true suppress warning.')  * running on http://127.0.0.1:5000/ (press ctrl+c quit) c:\envs\virtalenvs\flask_mini\lib\site-packages\sqlalchemy\sql\elements.py:3779: sawarning: textual sql expression 'select 1' should explicitly declared text('select 1') (this warning may suppressed after 10 occurrences)   {"expr": util.ellipses_string(element)}) 

what doing wrong?

seems you're connecting table, not db, correct? why don't change yournewdb postgres or make new db? you'll still have make table. can have sqlalchemy you. here great answer on that: https://stackoverflow.com/a/20749534/2326132

i'd suggest making new database each project, if test projects. you'll run fewer issues.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -