如何从另一个蓝图中调用一个蓝图的方法

时间:2016-03-02 05:36:39

标签: python flask

如何从另一个蓝图中调用一个蓝图的方法?

我有一个带有蓝图的Flask项目设置。

项目结构

rest
    __init__py
   rest_controller.py
web
    __init__.py
    web_controller.py
run.py

rest_controller.py

from flask import Flask, jsonify, Blueprint
from flask import request

blueprint = Blueprint('rest_controller', __name__)

@blueprint.route('/', methods=['GET'])
def index():
    return jsonify({'message': 'welcome'})

web_controller.py

from flask import Blueprint, render_template, redirect, url_for, session

blueprint = Blueprint('web_controller', __name__,
template_folder='templates', static_folder='static')

@blueprint.route('/')
def index():
    # want to call rest api index method
    return render_template('home.html')

run.py

from flask import Flask
import rest.rest_controller as rest_controller
import web.web_controller as web_controller

app = Flask(__name__)

app.register_blueprint(rest_controller.blueprint,url_prefix='/rest')
app.register_blueprint(web_controller.blueprint,url_prefix='/web')

if __name__ == '__main__':
    app.run(debug=True)

我想在Web控制器索引方法中调用REST服务索引方法。我怎么做?我尝试了请求包,但它无法正常工作。

1 个答案:

答案 0 :(得分:-1)

使用开发服务器只能处理一个连接,这意味着当您请求email-template.php时,您的服务器无法响应$subject_1, $body_1, $body_txt_1

您可以使用Uwsgi并将工作人员设置为超过1