나는 https://github.com/graup/flask-restless-security 코드를 잠시 동안 작동 시키려고했습니다. 이 코드를 내 코드에 통합하지 못한 후에는이 준비된 코드를 사용하기로 결정했습니다. 그러나 server.py를 실행하려고하면 아래 오류가 발생합니다. 오류의 원인은 플라스크 불안정한 사람의 동반자입니다. git에서 문제를 열었지만 프로젝트가 더 이상 유지되지 않습니다. 이 작품을 어떻게 만들 수 있습니까?응용 프로그램 등록되지 않았습니다. 플라스크 레스트가없는 오류
Traceback (most recent call last):
File "E:/WEB/Project1/app/server.py", line 62, in
include_columns=['id', 'data1', 'data2', 'user_id'])
File "E:\WEB\Project1\flask\lib\site-packages\flask_restless\manager.py", line 698, in create_api
blueprint = self.create_api_blueprint(app=app, *args, **kw)
File "E:\WEB\Project1\flask\lib\site-packages\flask_restless\manager.py", line 566, in create_api_blueprint
pk_name = primary_key or primary_key_name(model)
File "E:\WEB\Project1\flask\lib\site-packages\flask_restless\helpers.py", line 232, in primary_key_name
pk_names = primary_key_names(model)
File "E:\WEB\Project1\flask\lib\site-packages\flask_restless\helpers.py", line 214, in primary_key_names
return [key for key, field in inspect.getmembers(model)
File "c:\python27\Lib\inspect.py", line 252, in getmembers
value = getattr(object, key)
File "E:\WEB\Project1\flask\lib\site-packages\flask_sqlalchemy_init_.py", line 498, in get
return type.query_class(mapper, session=self.sa.session())
File "E:\WEB\Project1\flask\lib\site-packages\sqlalchemy\orm\scoping.py", line 78, in call
return self.registry()
File "E:\WEB\Project1\flask\lib\site-packages\sqlalchemy\util_collections.py", line 990, in call
return self.registry.setdefault(key, self.createfunc())
File "E:\WEB\Project1\flask\lib\site-packages\sqlalchemy\orm\session.py", line 2829, in call
return self.class_(**local_kw)
File "E:\WEB\Project1\flask\lib\site-packages\flask_sqlalchemy_init_.py", line 143, in init
self.app = app = db.get_app()
File "E:\WEB\Project1\flask\lib\site-packages\flask_sqlalchemy_init_.py", line 957, in get_app
'application not registered on db instance and no application'
RuntimeError: application not registered on db instance and no applicationbound to current context
server.py
from database import db
from application import app
from flask_restless import APIManager
from models import SomeStuff
apimanager = APIManager(app, flask_sqlalchemy_db=db)
apimanager.create_api(SomeStuff,
methods=['GET', 'POST', 'DELETE', 'PUT'],
url_prefix='/api/v1',
collection_name='free_stuff',
include_columns=['id', 'data1', 'data2', 'user_id'])
application.py
from flask import Flask
app = Flask(__name__)
app.config.from_object('config.DevelopmentConfig')
database.py
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
models.py
,451,515,from database import db
from flask_security import UserMixin, RoleMixin, SQLAlchemyUserDatastore
class SomeStuff(db.Model):
__tablename__ = 'somestuff'
id = db.Column(db.Integer, primary_key=True)
data1 = db.Column(db.Integer)
data2 = db.Column(db.String(10))
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
user = db.relationship(User, lazy='joined', join_depth=1, viewonly=True)
문제가 해결되었습니다. – krypt