python webapi

目的:将python代码写的功能模块封装成webapi
我首先用vs2017搭建python flask web项目

在runserver.py文件中
python webapi_第1张图片
init.py

"""
The flask application package.
"""

from flask import Flask
app = Flask(__name__)

import 自己的模块

runserver.py



from os import environ
from CAD import app

if __name__ == '__main__':
    #HOST = environ.get('SERVER_HOST', 'localhost')
    #try:
       # PORT = int(environ.get('SERVER_PORT', '5555'))
    #except ValueError:
        #PORT = 5555
    #app.run(HOST, PORT)
	app.run(host='127.0.0.1', port=8080, debug=True, threaded=True) #我这里用的是本地的,可以根据需要自己改

自己的py文件

"""
Routes and views for the flask application.
"""

from datetime import datetime
from flask import render_template
from FlaskWebProject1 import app


@app.route('/文件名/方法名',,methods=['GET', 'POST'])
def 自己的方法():
    """Renders the home page."""
    return render_template(
        'index.html',
        title='Home Page',
        year=datetime.now().year,
    )

你可能感兴趣的:(爱好)