1.一个HTML form input和一个button提供给用户输入
2.使用flask的request获取用户输入的文件名
3.判断输入异常
4.执行shell命令touch aa.txt 并返回ls查看的结果


pip install flask
filename.py
#!/bin/env python
# _*_coding:utf-8_*_
import os
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route('/', methods=['GET'])
def index():
return '''<form action="/" method="post">
<label>Filename:</label>
<input name="filename">
<input type="submit">
</form>'''
@app.route('/', methods=['POST'])
def get_sn():
filename= request.form['filename']
try:
filename.encode()
except Exception,e:
print Exception,":",e
return "Please check your input! like this:index.html aa.log"
os.popen('touch ' + filename).read()
out=os.popen('ls /var/tmp').read()
return '<h3> file: <br> %s </h3>' % out
if __name__ == '__main__':
app.run(host='0.0.0.0',port=5000,debug=True)
执行
python filename.py
本机浏览器localhost:5000
其他电脑:本机IP:5000