pythonanywhere网站db查询返回jsonify结果

时间:2017-07-31 07:11:46

标签: python pythonanywhere

我不了解pythonanywhere网站,如何返回json键值,但localhost只返回值不是键 ??

的env

1.flask

2.SQLAlchemy

3.mysql

4.python 2.7

我的课程

Base = declarative_base()
class DataEntity(Base):
      __tablename__ = 'data'
      id = Column("id", INTEGER, primary_key=True, nullable=False,autoincrement=True)
      clientid= Column("client_id", VARCHAR(32),nullable=False)
      name= Column("name", VARCHAR(10),nullable=False)
      description= Column("description", VARCHAR(20),nullable=False)

我的flask_app.py

engine = create_engine('mysql+mysqldb://xxx:xxx@xxx.mysql.pythonanywhere-services.com/xxx$dbname?charset=utf8', echo=True,pool_recycle=280)
Session = sessionmaker(bind=engine)
dbsession = Session()

@app.route('/api/data')
def getdata():
    data = dbsession.query(DataEntity.id,DataEntity.name).all();
    return jsonify({'data': data})

pythonanywhere网站json结果

{"data": [{"id": 1,"name": "name1"},{"id": 2,"name": "name2"}]}

本地json结果

{"data": [[1,"name1"],[2,"name2"]]}

0 个答案:

没有答案