我正在使用Flask
我总是收到错误消息“错误”:“列表”对象没有属性“ add_columns”。我试图对其进行谷歌搜索,但似乎没有人遇到类似的问题。
我正在使用mysql。
def index():
columns = [
ColumnDT(Rawlog.id),
ColumnDT(Rawlog.one),
ColumnDT(Rawlog.two),
ColumnDT(Rawlog.three)
]
query = session.query(Rawlog).all()
params = request.args.to_dict()
rowTable = DataTables(params, query, columns)
response = jsonify(rowTable.output_result())
response.headers.add('Access-Control-Allow-Origin', '*')
return response
如果我只是在没有数据表的情况下执行操作,它将获取所有行
usersArr = []
for user in query:
usersArr.append(user.toDict())
return jsonify(usersArr)
这是我的模特
# coding: utf-8
from app import db
from sqlalchemy import Column, DateTime, Integer, String
from sqlalchemy.schema import FetchedValue
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import inspect, ForeignKey
#db = SQLAlchemy()
Base = declarative_base()
class Base(db.Model):
__abstract__ = True
id = db.Column(db.Integer, primary_key=True)
class Rawlog(Base):
__tablename__ = 'rawlogs'
id = db.Column(db.Integer, primary_key=True)
one = db.Column(db.Integer)
two = db.Column(db.Integer)
three = db.Column(db.Integer)
four = db.Column(db.Integer)
def __init__(id, one, two, three, four):
self.id = id
self.one = one
self.two = two
self.three = three
self.four = four
def toDict(self):
return { c.key: getattr(self, c.key) for c in inspect(self).mapper.column_attrs }
我已在此处打开问题,但尚未回复
https://github.com/Pegase745/sqlalchemy-datatables/issues/114
我希望这里的任何人都能提供帮助。提前谢谢了。
[更新]
我试图按照给出的here的答案进行操作,似乎有所改变,这给了我错误
{"draw":"1","error":"int() argument must be a string or a number, not 'NoneType'","recordsFiltered":"108","recordsTotal":"108"}