本地一切正常,但是当我转到pythoneverywhere时出现错误:如果没有Flask-Migrate db,就无法从“ Data.Domain.User”导入名称“ User” ,我试图将Data.Domain.User模块的内容复制到app.py,并且可以正常工作,只是当我要将其移动到另一个文件夹(位置)时,问题才出现。
这是我在app.py中拥有的:
from flask import Flask
from flask_bcrypt import Bcrypt
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager, Server
from flask_migrate import Migrate, MigrateCommand
from flask_login import LoginManager
from flask_mail import Mail, Message
app = Flask(__name__)
app.config['SECRET_KEY'] = 'blablablastrongsecretkey'
app.config['SQLALCHEMY_DATABASE_URI'] = 'connstring'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
login_manager = LoginManager(app)
from Data.Domain.User import User
from Presentation import App
if __name__ == '__main__':
manager.run()
Module Data.Domain.User是这个:
from app import db, login_manager
from flask_login import UserMixin
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
uuid = db.Column(db.String(50), unique=True)
username = db.Column(db.String(40), unique=True)
def __repr__(self):
return "User(\n\tID: " + str(self.uuid) + "\n\tUsername: " + self.username + "\n)"
答案 0 :(得分:1)
我解决了重命名app.py文件并将其移动到另一个文件夹中的问题,然后我刚刚从其中导入了应用程序
from Presentation.Server import app
这是从Data.Domain.User文件导入的