print (type(Archive.query.filter_by))
print (type(Archive.query.filter_by(archive_name='aaa')))
print (Archive.query.filter_by(archive_name='aaa'))
print (type(Archive.query.filter_by(archive_name='aaa').first))
print (type(Archive.query.filter_by(archive_name='aaa').first()))
<type 'instancemethod'>
<class 'flask_sqlalchemy.BaseQuery'>
SELECT flask_archive.id AS flask_archive_id, flask_archive.archive_name AS flask_archive_archive_name
FROM flask_archive
WHERE flask_archive.archive_name = :archive_name_1
<type 'instancemethod'>
最后一个没有输出,也没有错误提示就退出了。pdb调试 出现
"The program exited via sys.exit(). Exit status: -9"
引用关系,
主app 在myapp.py
from flask import Flask
app = Flask(__name__)
app.config.from_object('config')
from views import *
if '__main__' == __name__:
□□□□app.debug = True
□□□□app.run()
views.py
from models import Archive, Tag, Comment, Post, db
@app.route('/blabla')
def index():
□□□□print (type(Archive.query.filter_by))
□□□□print (type(Archive.query.filter_by(archive_name='aaa')))
□□□□print (Archive.query.filter_by(archive_name='aaa'))
□□□□print (type(Archive.query.filter_by(archive_name='aaa').first))
□□□□print (type(Archive.query.filter_by(archive_name='aaa').first()))
□□□□a = Archive.query.filter_by(archive_name='aaa').first()
□□□□return "Hello world"
models.py
from myapp import app
from flask.ext.sqlalchemy import SQLAlchemy, BaseQuery
db = SQLAlchemy(app)
class Archive(db.Model):
□□□□pass
class Tag(db.Model):
□□□□pass
以上代码简化了的
1
wuyu1998 2015-01-21 11:53:35 +08:00
将所以的from xxx import *改为import xxx
|
2
wuyu1998 2015-01-21 11:55:36 +08:00
|
3
wuyu1998 2015-01-21 11:58:10 +08:00
删除myapp.py中的
from views import * |
4
wuyu1998 2015-01-21 12:00:18 +08:00
最关键的问题,models.py中没有建立字段,无法和数据库的表建立映射关系。
class Archive(db.Model): □□□□pass |
5
happywowwow OP |