提交 8ef49c8b 编写于 作者: H hjdhnx

新增文件上传功能

上级 cf810f21
......@@ -15,6 +15,7 @@ warnings.filterwarnings('ignore')
import os
from flask import Flask, jsonify, abort,request,redirect,make_response,render_template,send_from_directory,url_for
from werkzeug.utils import secure_filename
from js.rules import getRuleLists
from utils import error,parser
from utils.web import *
......@@ -117,6 +118,26 @@ def login_api():
else:
return jsonify(error.failed('登录失败,用户名或密码错误'))
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
cookies = request.cookies
# print(cookies)
token = cookies.get('token', '')
# print(f'mytoken:{token}')
if not verfy_token(token):
return render_template('login.html')
if request.method == 'POST':
f = request.files['file']
# print(request.files)
filename = secure_filename(f.filename)
savePath = f'js/{filename}'
# print(savePath)
f.save(savePath)
return jsonify(error.success('文件上传成功'))
else:
# return render_template('upload.html')
return jsonify(error.failed('文件上传失败'))
@app.route('/vod')
def vod():
t0 = time()
......
......@@ -12,5 +12,9 @@
<body>
<h2 class="title">欢迎使用py_dr管理员界面</h2>
<p>你可以在此页面在线上传规则文件到js目录或者删除js目录的文件</p>
<form action = "/upload" method = "POST" enctype = "multipart/form-data">
<input type = "file" name = "file" />
<input type = "submit" value="提交"/>
</form>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册