web框架:
這個很繁瑣,心態容易崩。
flask安裝:指定阿里雲進行安裝
具體源碼:
pycharm中:ALT+ENTER是個好用法
from flask import Flask
app = Flask(__name__)
@app.route('/hello_world', methods=['GET', 'POST'])
def hello_world():
from flask import request
#兩種不同的提交方式判斷
if request.method == 'GET':
#可以構造XSS攻擊腳本
#如:%3cscript%3ealert%28%27hehe%27%29%3c%2fscript%3e
#對應:<script>alert('hehe')</script>
#一般瀏覽器會檢測到,並提示:錯誤代碼 ERR_BLOCKED_BY_XSS_AUDITOR
name = request.args.get('name')
pwd = request.args.get('pwd')
return '''
<form action="/hello_world" method="post">
<input name="name" placeholder="用戶名"><br>
<input name="pwd" placeholder="密碼"><br>
<button>確認</button>
</form>
<p>用戶名:%s</p>
<p>密碼:%s</p>
''' % (name, pwd)
else:
name = request.form.get('name')
pwd = request.form.get('pwd')
return '''
<script>alert('hehe')</script>
<p>用戶名:%s</p>
<p>密碼:%s</p>
''' % (name, pwd)
獲取表單數據也可以這麼寫:
if __name__ == '__main__':
app.run()