文档服务地址:http://47.92.0.57:3000/ 周报索引地址:http://47.92.0.57:3000/s/NruNXRYmV

Commit 29108bba by 李景熙

修改上传文件的相关代码,将数据库配置统一移到model文件中

parent fedc9736
...@@ -367,7 +367,7 @@ ...@@ -367,7 +367,7 @@
if(res.code == 0) if(res.code == 0)
alert("文件上传失败,请重新上传"); alert("文件上传失败,请重新上传");
else{ else{
console(res.data.url); console(res.data);
} }
}) })
}, },
......
from peewee import * from peewee import *
from Dao.model import mysql
mysql = MySQLDatabase(
'sys',
host='127.0.0.1',
user='root',
passwd='root',
charset='utf8'
)
mysql.connect()
class Data(Model): class Data(Model):
......
from peewee import * from peewee import *
from Dao.model import mysql
import datetime import datetime
mysql = MySQLDatabase(
'sys',
host='127.0.0.1',
user='root',
passwd='root',
charset='utf8'
)
mysql.connect()
class Result: class Result:
code: int code: int
......
from Dao import Task from Dao import Task
from peewee import * from peewee import *
from Dao.model import mysql
mysql = MySQLDatabase(
'sys',
host='127.0.0.1',
user='root',
passwd='root',
charset='utf8'
)
mysql.connect()
class Result: class Result:
code: int code: int
......
...@@ -2,17 +2,7 @@ from peewee import * ...@@ -2,17 +2,7 @@ from peewee import *
import datetime import datetime
import math import math
from Dao import User from Dao import User
from Dao.model import mysql
mysql = MySQLDatabase(
'sys',
host='127.0.0.1',
user='root',
passwd='root',
charset='utf8'
)
mysql.connect()
class Result: class Result:
code: int code: int
......
from peewee import * from peewee import *
from Dao.model import mysql
mysql = MySQLDatabase(
'sys',
host='127.0.0.1',
user='root',
passwd='root',
charset='utf8'
)
mysql.connect()
class Result: class Result:
code: int code: int
...@@ -175,7 +165,5 @@ def get_username(id): ...@@ -175,7 +165,5 @@ def get_username(id):
return tmp.userName return tmp.userName
if __name__ == '__main__': if __name__ == '__main__':
register('admin', 'admin', 'admin') User.create_table()
set_type(3, 1)
# User.create_table()
from flask import Flask from flask import Flask
from flask_cors import CORS from flask_cors import CORS
from views.uploadDownload import uploadDownload from views.uploadDownload import uploadDownload
# from views.textAnnotation import textAnnotation # from views.textAnnotation import textAnnotation
from views.user import user from views.user import user
...@@ -11,6 +9,7 @@ from views.slice import slice ...@@ -11,6 +9,7 @@ from views.slice import slice
from config.config import DevelopmentConfig from config.config import DevelopmentConfig
app = Flask(__name__) app = Flask(__name__)
CORS(app) CORS(app)
app.config.from_object(DevelopmentConfig) app.config.from_object(DevelopmentConfig)
......
...@@ -22,7 +22,6 @@ def allowed_file(filename): ...@@ -22,7 +22,6 @@ def allowed_file(filename):
# 上传文件 # 上传文件
@uploadDownload.route('/upload', methods=['POST'], strict_slashes=False) @uploadDownload.route('/upload', methods=['POST'], strict_slashes=False)
def upload(): def upload():
print("1")
file_dir = os.path.join(basedir, UPLOAD_FOLDER) file_dir = os.path.join(basedir, UPLOAD_FOLDER)
if not os.path.exists(file_dir): if not os.path.exists(file_dir):
os.makedirs(file_dir) os.makedirs(file_dir)
...@@ -33,12 +32,9 @@ def upload(): ...@@ -33,12 +32,9 @@ def upload():
unix_time = int(time.time()) unix_time = int(time.time())
new_filename = str(unix_time)+'.'+ext # 修改了上传的文件名 new_filename = str(unix_time)+'.'+ext # 修改了上传的文件名
f.save(os.path.join(file_dir, new_filename)) # 保存文件到upload目录 f.save(os.path.join(file_dir, new_filename)) # 保存文件到upload目录
print(new_filename) return jsonify({"code": 1, "msg": "succeed ", "data": "http://127.0.0.1:9100/api/files/download/"+new_filename})
return jsonify({"errno": 0, "msg": "succeed ", "token": new_filename})
else: else:
return jsonify({"errno": 1001, "errmsg": u"failed"}) return jsonify({"code": 0, "errmsg": u"failed"})
# 下载接口 # 下载接口
@uploadDownload.route('/download/<fileName>', methods=['GET']) @uploadDownload.route('/download/<fileName>', methods=['GET'])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment