windows 下
目录结构
home.py
#import os
#import json
#import re
#import pandas as pd
#import unicodedata
#from datetime import datetime
#from pathlib import Path
#from flaskr.logger import logging
#from werkzeug.utils import secure_filename
from flask import (
Blueprint, flash, g, redirect, render_template, request, Response, session, url_for, jsonify, send_file
)
bp = Blueprint('home', __name__, url_prefix='/MQ')
@bp.route('heartbeat', methods=('GET', "POST"))
def heartbeat():
return "alive"
main.py
import os
from flask import Flask
from flask_cors import CORS
def create_app(test_config=None):
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
CORS(app, supports_credentials=True)
app.config.from_mapping(
SECRET_KEY='dev',
DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
MAX_CONTENT_LENGTH= 500 * 1024 * 1024
)
if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile('config.py', silent=True)
else:
# load the test config if passed in
app.config.from_mapping(test_config)
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
# a simple page that says hello
import home
app.register_blueprint(home.bp)
#app.register.blueprint(run.bp)
return app
app = create_app()
if __name__ == '__main__':
app.run(host='0.0.0.0' , port= '9999', debug=True)
init.py (非必要)
运行方式
python main.py
访问测试
linux 下
home.py 内容相同,main.py 去掉
init.py
import os
from flask import Flask
from flask_cors import CORS
def create_app(test_config=None):
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
CORS(app, supports_credentials=True)
app.config.from_mapping(
SECRET_KEY='dev',
DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
MAX_CONTENT_LENGTH= 500 * 1024 * 1024
)
if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile('config.py', silent=True)
else:
# load the test config if passed in
app.config.from_mapping(test_config)
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
# a simple page that says hello
import home
app.register_blueprint(home.bp)
#app.register.blueprint(run.bp)
return app
运行方式
## 开发模式
export FLASK_APP=flaskr
export FLASK_ENV=development
flask run -h 0.0.0.0 -p 9999
## 生产模式
export FLASK_APP=flaskr
nohup gunicorn -t 300 -w 1 -b 0.0.0.0:9999 'flaskr:create_app()'