Flask项目里面,如何同时使用MySQL和MongoDB,Sqlalchemy和MongoEngine?


Flask项目里面,如何同时使用MySQL和MongoDB,Sqlalchemy和MongoEngine?


 from mongoengine import *  
import datetime

class Page(Document):  
    title = StringField(max_length=200, required=True)  
    date_modified = ateTimeField(default=datetime.datetime.now)
    author = xxxx????【这里怎么关联到User呢?? 手工?】


=======
from sqlalchemy import Column, Integer, String
class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    name = Column(String)
    fullname = Column(String)
    password = Column(String)

flask mongoengine mongodb

世纪末中二传说 11 years, 11 months ago

两种数据库,没法互相引用。手动吧。给 Page 写一个 property,比如 get_user 什么的。

一只小小鸟 answered 11 years, 11 months ago

把函数放在不同的package里不行么?

江汉热线线长 answered 11 years, 11 months ago

Your Answer