flask-admin问题

from flask import Flask  
from flask_admin import Admin  
from flask.ext.admin.contrib.sqla import ModelView  
from app import db  

app=Flask(__name__)  
admin=Admin(app,name='microblog')  
admin.add_view(ModelView(User,db.session))  
db.init_app(app)  

if __name__=="__main__":  
    app.run()

我运行提示我说:ImportError: No module named flask.ext.admin.contrib.sqla

Traceback (most recent call last):
  File "manage.py", line 3, in <module>
    from flask.ext.admin.contrib.sqla import ModelView
  File "/home/alvy/Desktop/flask-admin/venv/local/lib/python2.7/site-packages/flask/exthook.py", line 87, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named flask.ext.admin.contrib.sqla

我修改成from flask_admin.contrib.sqla import ModelView也不行 提示说ImportError: No module named sqla

我已经安装了flask-admin 我是还需要安装什么吗?


app文件夹里包含__init__.py文件和models.py文件,__init__.py为:

from flask.ext.sqlalchemy import SQLAlchemy

db=SQLAlchemy()

models.py文件为:

from . import db

class Role(db.Model):
    __tablename__='roles'
    id=db.Column(db.Integer,primary_key=True)
    name=db.Column(db.String(64),unique=True)
    users=db.relationship('User',backref='role',lazy='dynamic')

    def __repr__(self):
        return '<Role %r>' % self.name

class User(db.Model):
    __tablename__='users'
    id=db.Column(db.Integer,primary_key=True)
    username=db.Column(db.String(64),unique=True,index=True)
    role_id=db.Column(db.Integer,db.ForeignKey('roles.id'))

requirements.txt为:
Flask==0.10.1
Flask-Admin==1.0.3
Flask-SQLAlchemy==2.1
Flask-WTF==0.12
Jinja2==2.8
MarkupSafe==0.23
SQLAlchemy==1.0.9
WTForms==2.0.2
Werkzeug==0.11.2
argparse==1.2.1
itsdangerous==0.24
wsgiref==0.1.2

17 comments