一个或多个地图制作工具无法初始化

时间:2016-04-26 20:02:40

标签: python flask

我遇到了SQLALCHEMY的问题,我实际上是使用FLASK micro-framework创建了我的博客,并在digitalocean.com上运行

我已经安装了运行博客所需的所有要求,uwsgi运行得非常好,但是当我启动apache时,它给出了一个错误说:

InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Original exception was: Multiple classes found for path "Category" in the registry of this declarative base. Please use a fully module-qualified path.

我现在实际上不知道为什么会出现这个错误,实际上在我的本地主机上,博客的效果非常好。

这是型号代码:

from flask_blog import db, uploaded_images, uploaded_book, uploaded_video, app
from datetime import datetime


import sys
if sys.version_info >= (3, 0):
    enable_search = False
else:
    enable_search = True
    import flask.ext.whooshalchemy as whooshalchemy



class Blog(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    admin = db.Column(db.Integer, db.ForeignKey('user.id'))

    def __init__(self, name, admin):
        self.name = name
        self.admin = admin

    def __repr__(self):
        return "<Name %r>" %self.name

class Post(db.Model):

    __searchable__ = ['body']

    id = db.Column(db.Integer, primary_key=True)
    blog_id = db.Column(db.Integer, db.ForeignKey('blog.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    title = db.Column(db.String(80))
    body = db.Column(db.String(140))
    image = db.Column(db.String(255))
    book = db.Column(db.String(255))
    price = db.Column(db.Float)
    video = db.Column(db.String(255))
    slug = db.Column(db.String(256), unique=True)
    publish_date = db.Column(db.DateTime)
    live = db.Column(db.Boolean)

    category_id = db.Column(db.Integer, db.ForeignKey('category.id'))
    category = db.relationship('Category', backref=db.backref('posts', lazy='dynamic'))
    comments = db.relationship('Comment', backref='post', lazy='dynamic')

    @property
    def imgsrc(self):
        return uploaded_images.url(self.image)

    @property
    def booksrc(self):
        return uploaded_book.url(self.book)

    @property
    def videosrc(self):
        return uploaded_video.url(self.video)

    def __init__(self, blog, author, title, body, category, slug, image=None, book=None, video=None, publish_date=None, live=True):
        self.blog_id = blog.id
        self.user_id = author.id
        self.title = title
        self.body = body
        self.category = category
        self.slug = slug
        self.image = image
        self.book = book
        self.video = video

        if publish_date is None:
            self.publish_date = datetime.utcnow()
        self.live = live

    def __repr__(self):
        return "<Post %r>" % self.title

class Purchase(db.Model):
    uuid = db.Column(db.String(128), primary_key=True)
    email = db.Column(db.String(50))
    product_id = db.Column(db.Integer, db.ForeignKey('post.id'))
    product = db.relationship(Post)
    downloads_left = db.Column(db.Integer, default=5)
    sold_at = db.Column(db.DateTime, default=datetime.now)

    def sell_date(self):
        return self.sold_at.date()

    def __str__(self):
        return '{} bought by {}'.format(self.product.name, self.email)

class Category(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))

    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return self.name


class Comment(db.Model):
    __tablename__ = 'comments'
    id = db.Column(db.Integer, primary_key=True)
    body = db.Column(db.Text)
    body_html = db.Column(db.Text)
    timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
    disabled = db.Column(db.Boolean)
    author_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    post_id = db.Column(db.Integer, db.ForeignKey('post.id'))

    @staticmethod
    def on_changed_body(target, value, oldvalue, initiator):
        allowed_tags = ['a', 'abbr', 'acronym', 'b', 'code', 'em', 'i',
                        'strong']
        target.body_html = bleach.linkify(bleach.clean(
            markdown(value, output_format='html'),
            tags=allowed_tags, strip=True))

db.event.listen(Comment.body, 'set', Comment.on_changed_body)

if enable_search:
    whooshalchemy.whoosh_index(app, Post)

还有views.py片段:

@app.route('/')
@app.route('/index/')
@app.route('/index/<int:page>')
def index(page=1):
    blog = Blog.query.first()
    posts = Post.query.filter_by(live=False).order_by(Post.publish_date.desc()).paginate(page, POSTS_PER_PAGE, False)
    cates = Category.query.all()
    execlusives = Post.query.join(Category, Category.id == Post.category_id).filter(Category.name == 'exclusives').filter(Post.live == True).order_by(Post.publish_date.desc()).all()
    clever = Post.query.join(Category, Category.id == Post.category_id).filter(Category.name == 'clever').filter(Post.live == True).order_by(Post.publish_date.desc()).all()
    return render_template('blog/index.html', blog=blog, posts=posts, cates=cates, execlusives=execlusives,clever=clever)

以下是调试器的更多信息:

Traceback (most recent call last)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/var/www/FlaskApp/FlaskApp/blog/views.py", line 23, in index
blog = Blog.query.first()
File "/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy/__init__.py", line 498, in __get__
mapper = orm.class_mapper(type)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/base.py", line 421, in class_mapper
mapper = _inspect_mapped_class(class_, configure=configure)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/base.py", line 400, in _inspect_mapped_class
mapper._configure_all()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 1167, in _configure_all
configure_mappers()
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 2765, in configure_mappers
raise e
InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Original exception was: Multiple classes found for path "Category" in the registry of this declarative base. Please use a fully module-qualified path.

最终,如果有人知道从哪里开始编辑代码,那将非常感谢,谢谢:)。

0 个答案:

没有答案