阿里云函數(shù)制作靜態(tài)web頁面
1、登陸賬號,進(jìn)入到函數(shù)計算控制臺https://fc.console.aliyun.com/fc/ 選擇要創(chuàng)建函數(shù)的所在區(qū)域
2、點擊左側(cè)服務(wù)及函數(shù)后創(chuàng)建服務(wù),新增函數(shù),選擇flask-web模版進(jìn)行創(chuàng)建,并選擇http觸發(fā)器

?
?3、進(jìn)入函數(shù),選擇代碼執(zhí)行

?
?4、右擊點擊創(chuàng)建文件,創(chuàng)建index.html文件(可用word另存為進(jìn)行生成

?
?5、修改main.py文件
#!/usr/bin/env python # coding=utf-8from flask import Flask,send_filefrom 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)
點擊右上角部署,自定義域名后即可訪問
鏈接:https://www.dianjilingqu.com/523787.html