1、登陆账号,进入到函数计算控制台https://fc.console.aliyun.com/fc/ 选择要创建函数的所在区域
2、点击左侧服务及函数后创建服务,新增函数,选择flask-web模版进行创建,并选择http触发器
3、进入函数,选择代码执行
4、右击点击创建文件,创建index.html文件(可用word另存为进行生成
5、修改main.py文件
#!/usr/bin/env python # coding=utf-8 from flask import Flask,send_file from flask import request from flask import make_response try: from urllib.parse import urlparse except: from urlparse import urlparse app = Flask(__name__) base_path = ‘‘ @app.route(‘/‘, methods=[‘GET‘, ‘POST‘]) def home(): # resp = make_response(‘<h3>home<h3>‘, 200) return send_file("index.html") @app.route(‘/signin‘, methods=[‘GET‘]) def signin_form(): global base_path html = ‘‘‘<form action="{}/signin" method="post"> <p><input name="username"></p> <p><input name="password" type="password"></p> <p><button type="submit">Sign In</button></p> </form>‘‘‘.format(base_path) resp = make_response(html, 200) return resp @app.route(‘/signin‘, methods=[‘POST‘]) def signin(): if request.form[‘username‘]==‘admin‘ and request.form[‘password‘]==‘password‘: html = ‘<h3>Hello, admin!</h3>‘ else: html = ‘<h3>Bad username or password.</h3>‘ resp = make_response(html, 200) return resp def handler(environ, start_response): parsed_tuple = urlparse(environ[‘fc.request_uri‘]) li = parsed_tuple.path.split(‘/‘) global base_path if not base_path: base_path = "/".join(li[0:5]) return app(environ, start_response)
点击右上角部署,自定义域名后即可访问