导入并从烧瓶_CORS导入后,我将获得Blask Server来支持Localhost的请求。但是,只有该请求在API.ROUTE。
下对于命名空间下的任何目标,我从arount'http://localhost:3000'从http://127.0.1:5151/api/hello2'获取访问获取被CORS策略阻止
app.py
app = Flask(__name__)
CORS(app, resources={r"/*": {"origins":"*"}})
...
...
def initialize_app(flask_app):
"""
Register blueprints and append all namespaces
"""
blueprint = Blueprint('api', __name__, url_prefix='/api')
api.init_app(blueprint)
api.add_namespace(hello_namespace)
flask_app.register_blueprint(blueprint)
restplus.py
api = Api(version='1.0', title='API', description='API ...')
@api.route('/hello')
class HelloWorld(Resource):
def get(self):
return {'hello': 'world from API'}
namespace.py
ns = api.namespace('hello2', description='Hello endpoints')
@ns.route('/')
@api.doc(responses={404: 'Failed to connect'}, description='List all')
class HelloList(Resource):
def get(self):
return [{'hello': 'world from API'}]
从http://127.0.0.1:5151/api/hello Works获取数据。http://127.0.0.1:5151/api/hello2给我一个错误。
请指向正确的方向。
corydolphin 在2016年3月18日评论https://github.com/corydolphin/flask-cors/issues/128#issuecomment-198453999
"我希望发生的事情是烧瓶是从'foo''重新定向到'foo/'的。烧瓶会自动这样做。"
通过将尾斜线添加到客户端的请求中来打开。http://127.0.0.1:5151/api/hello2/现在正在工作。