我正在尝试为 sqlalchemy 数据库制作 Restful 端点。但由于某种原因,它找不到 Flask Restless 扩展。
当我运行该文件时,我收到此错误:
Traceback (most recent call last):
File "./rest1.py", line 7, in <module>
import flask.ext.restless
File "/home/ian/git_dev/flask_rest/test2/flask/local/lib/python2.7/site-packages/flask/exthook.py", line 86, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named flask.ext.restless
我安装了 Flask、Flask-Restless 和 SQLalchemy,但它仍然无法工作。
Django==1.6.5
Flask==0.10.1
Flask-Restless==0.13.1
Jinja2==2.7.2
MarkupSafe==0.23
PAM==0.4.2
Pillow==2.3.0
SQLAlchemy==0.9.4
这是我的代码:
#!flask/bin/python
#!/usr/bin/python
# -*- mode: python -*-
from flask import Flask
from sqlalchemy import Column, Date, DateTime, Float, Integer, Unicode
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
import flask.ext.restless
app = Flask(__name__)
engine = create_engine('sqlite:////tmp/testdb.sqlite', convert_unicode=True)
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
mysession = scoped_session(Session)
Base = declarative_base()
Base.metadata.bind = engine
class Test_Table(Base):
__tablename__ = 'plot'
id = Column(DateTime, primary_key=True)
value = Column(Integer)
type = Column(Unicode)
max = Column(Integer)
min = Column(Integer)
Base.metadata.create_all()
manager = flask.ext.restless.APIManager(app, flask_sqlalchemy_db=db)
manager.create_api(Test_Table, methods=['GET', 'POST', 'PUT' 'DELETE'])
app.run()
我也尝试过 Flask-Restful,无论是在虚拟环境内部还是外部。但我仍然得到相同的结果。