Skip to content

Commit fadb2ff

Browse files
committed
update:修改文件结构,存储文件不再暴露,自定义数据都放在/data文件夹,方便docker
1 parent cc2a02c commit fadb2ff

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
media/
22
logs/
33
.idea
4-
/static/upload
4+
/data
55
__pycache__/
66
*.py[cod]
77
*$py.class
@@ -111,7 +111,7 @@ celerybeat.pid
111111
*.sage.py
112112

113113
# Environments
114-
.env
114+
data/.env
115115
.venv
116116
env/
117117
venv/
@@ -150,6 +150,6 @@ for_test.py
150150
.html
151151
/evaluate/temp.py
152152
/evaluation/back.json
153-
.env*
153+
data/.env
154154
.backup/
155155
/cloc-1.64.exe

database.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import datetime
2-
32
from sqlalchemy import Boolean, Column, Integer, String, DateTime
43
from sqlalchemy.ext.declarative import declarative_base
54
from sqlalchemy.ext.asyncio import create_async_engine
65
from sqlalchemy.ext.asyncio.session import AsyncSession
7-
8-
engine = create_async_engine("sqlite+aiosqlite:///database.db")
6+
import settings
7+
engine = create_async_engine(settings.DATABASE_URL)
98

109
Base = declarative_base()
1110

main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
DATA_ROOT = Path(settings.DATA_ROOT)
2323
if not DATA_ROOT.exists():
2424
DATA_ROOT.mkdir(parents=True)
25-
# 静态文件夹
26-
app.mount(settings.STATIC_URL, StaticFiles(directory=DATA_ROOT), name="static")
25+
26+
# 静态文件夹,这个固定就行了,静态资源都放在这里
27+
app.mount(settings.STATIC_URL, StaticFiles(directory='./static'), name="static")
2728

2829

2930
@app.on_event('startup')

settings.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
from starlette.config import Config
22

33
# 配置文件.env
4-
config = Config(".env")
4+
# 请将.env移动至data目录,方便docker部署
5+
config = Config("data/.env")
56
# 是否开启DEBUG模式
67
DEBUG = config('DEBUG', cast=bool, default=False)
78
# 端口
89
PORT = config('PORT', cast=int, default=12345)
910
# Sqlite数据库文件
10-
DATABASE_URL = config('DATABASE_URL', cast=str, default="sqlite+aiosqlite:///database.db")
11-
# 静态文件夹
12-
DATA_ROOT = config('DATA_ROOT', cast=str, default="./static")
11+
DATABASE_URL = config('DATABASE_URL', cast=str, default="sqlite+aiosqlite:///data/database.db")
12+
# 数据存储文件夹,文件就不暴露在静态资源里面了
13+
DATA_ROOT = './data/' + config('DATA_ROOT', cast=str, default=f"static")
1314
# 静态文件夹URL
1415
STATIC_URL = config('STATIC_URL', cast=str, default="/static")
1516
# 错误次数

templates/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,9 @@
306306
}
307307
},
308308
successUpload(response, file, fileList) {
309+
console.log(response)
309310
this.$message({
310-
message: response.msg,
311+
message: response.detail,
311312
type: 'success'
312313
});
313314
this.files.unshift(response.data);

0 commit comments

Comments
 (0)