私はpeewee ORMを使用していましたが、postgresqlデータベースを作成しました.3つのスクリプトをcreateTableとaddUserとdropTableに作成しましたが、うまくいきました。表示されます。そのようなテーブルの上:ユーザー 私のコードのいくつかあります。 confiuration.pyはこのテーブルのpeewee
class Configuration(object):
DATABASE = 'postgresql://lc:********@localhost:5432/wolfsly'
@staticmethod
def init_app(app):
pass
app.py
# -*- coding: utf-8 -*-
from flask import Flask
from .extensions import db, lm
from .configuration import config
_all_ = ['create_app']
def create_app(config_name):
app = Flask(__name__)
app.config.from_object(config[config_name])
config_blueprint(app)
configure_template_filters(app)
config_extensions(app)
return app
def config_extensions(app):
db.init_app(app)
extensions.py
# -*- coding: utf-8 -*-
from playhouse.flask_utils import FlaskDB
from flask_login import LoginManager
lm = LoginManager()
db = FlaskDB()
と私のデータベーススクリプトの1 createTable.py
# -*- coding: utf-8 -*-
from application import create_app
from application.extensions import db
def createTables():
app = create_app('default')
from application.models import (User, Project, Photo)
database = db.database
database.connect()
database.create_tables([User, Project, Photo])
database.close()
if __name__ == '__main__':
createTables()
私はよく、私のデータベースにそれがうまく私のcreateTable.pyを実行する3つのテーブルを表示され、アドユーザーの後に私のユーザーテーブル内の正常なデータがある場合には。しかし、ユーザーテーブルのユーザーまたはユーザーテーブルのクエリデータを取得しようとすると、「そのようなテーブルに:ユーザー」と私の仕事のディレクトリにpeewee.dbが表示されます。 ここに私の認証書/ views.pyのいくつかのコードがあります
# -*- coding: utf-8 -*-
from flask import render_template, redirect, url_for, flash
from flask_login import current_user, login_user
from ..models import User
from . import bpAuth
@bpAuth.route('/login')
def login():
pass
@bpAuth.route('/test')
def test():
query = User.select(User.id, User.chinesename)
print 'test'
names = [user.chinesename for user in query]
for user in query:
print user.chinesename
u = User.get(User.username == 'lc')
print u.chinesename
return u.chinesename
、ここでいくつかのスクリーンショット
[enter image description here][1]
[enter image description here][2]
[enter image description here][3]
[1]: https://i.stack.imgur.com/tWLYo.jpg
[2]: https://i.stack.imgur.com/ldBRV.jpg
[3]: https://i.stack.imgur.com/f0Tb7.jpg
あり、私が私のWebアプリケーションを実行したとき、私は私のローカルデータベースに接続することはできませんようです。
置く完全なエラーメッセージを。完全なメッセージ - そのような表の上だけでなく、ユーザー "' - 他の有用な情報があるかもしれないので、どのラインが問題になるか。 – furas