Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flask 如何开始不安的生活_Flask_Flask Sqlalchemy_Flask Restless - Fatal编程技术网

Flask 如何开始不安的生活

Flask 如何开始不安的生活,flask,flask-sqlalchemy,flask-restless,Flask,Flask Sqlalchemy,Flask Restless,我不知道该怎么做才好 蓝图api: # coding: utf-8 from flask import Blueprint, render_template from ..models import User from flask_restless import APIManager manager = APIManager() manager.create_api(User, url_prefix='/api', methods=['GET', 'POST', 'DELETE', 'PUT

我不知道该怎么做才好

蓝图api:

# coding: utf-8
from flask import Blueprint, render_template
from ..models import User
from flask_restless import APIManager

manager = APIManager()

manager.create_api(User, url_prefix='/api', methods=['GET', 'POST', 'DELETE', 'PUT', 'PATCH'])

bp = Blueprint('api', __name__)
\uuuu init\uuuuu.py

def register_db(app):
    from .models import db

    db.init_app(app)

def register_api(app):
    from .controllers.api import manager

    manager.init_app(app, flask_sqlalchemy_db=db)
注册蓝图:

def register_routes(app):
    from . import controllers
    from flask.blueprints import Blueprint
for module in _import_submodules_from_package(controllers):
    bp = getattr(module, 'bp')
    if bp and isinstance(bp, Blueprint):
        app.register_blueprint(bp)
尝试启动时出现以下错误:

运行时错误:应用程序未在db实例上注册,且没有绑定到当前上下文的应用程序

如果排除方法=['GET'、'POST'、'DELETE'、'PUT'、'PATCH'],则应用程序将启动,但如果尝试发送请求http,显然会得到答案:

HTTP/1.0 500 INTERNAL SERVER ERROR
Content-Length: 291
Content-Type: text/html
Date: Thu, 20 Oct 2016 15:33:52 GMT
Server: Werkzeug/0.11.11 Python/3.5.2
没有给出解决问题的例子

你能告诉我在哪里可以找到答案吗?这是有效的:

蓝图:

# coding: utf-8
from flask import Blueprint, render_template
from flask_restless import APIManager
from ..models import db


bp = Blueprint('api', __name__)

manager = APIManager(flask_sqlalchemy_db=db)
init.py:

def register_api(app):
    """Register api."""
    from .controllers.api import manager
    from .models import User

    manager.init_app(app)
    manager.create_api(User, app=app)
请求:
httphttp://0.0.0.0:5000/api/user

答复:

HTTP/1.0 200 OK
Content-Length: 72
Content-Type: application/json
Content-Type: application/json
Date: Thu, 20 Oct 2016 18:50:04 GMT
Link: <http://0.0.0.0:5000/api/user?page=0&results_per_page=10>; rel="last"
Link: <http://0.0.0.0:5000/api/user?page=0&results_per_page=10>; rel="last"
Server: Werkzeug/0.11.11 Python/3.5.2
Vary: Accept

{
  "num_results": 0,
  "objects": [],
  "page": 1,
  "total_pages": 0
}
HTTP/1.0 200正常
内容长度:72
内容类型:application/json
内容类型:application/json
日期:2016年10月20日星期四格林威治标准时间18:50:04
链接:;rel=“last”
链接:;rel=“last”
服务器:Werkzeug/0.11.11 Python/3.5.2
更改:接受
{
“num_结果”:0,
“对象”:[],
“页码”:1,
“总页数”:0
}