-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (51 loc) · 1.82 KB
/
main.py
File metadata and controls
65 lines (51 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from flask_sqlalchemy import SQLAlchemy
from flask import Flask, app, render_template, sessions, request, url_for
from flask import flash
from werkzeug.utils import redirect, secure_filename
import os
import pymysql
pymysql.install_as_MySQLdb()
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:200189ymy@127.0.0.1:3306/web_db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = '123'
db = SQLAlchemy(app)
class File(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Text)
bz = db.Column(db.Text)
path = db.Column(db.Text)
db.create_all()
@app.route('/sjj', methods=['GET', 'POST'])
def sjj():
if request.method == 'POST':
f = request.files.get('wjsc')
bzhu = request.form.get('beizhu')
basepath = os.path.dirname(__file__) # 当前文件所在路径
upload_path = os.path.join(basepath, r'static\uploads', secure_filename(f.filename))
f.save(upload_path)
fl = File(name=secure_filename(f.filename), bz=bzhu)
db.session.add(fl)
db.session.commit()
flash('successful!')
return redirect(url_for('sjj'))
file_list = File.query.all()
return render_template('sjj.html', file_list=file_list)
@app.route('/delete/<int:file_id>', methods=['GET', 'POST'])
def delete(file_id):
if request.method == 'POST':
fd = File.query.get_or_404(file_id)
db.session.delete(fd)
db.session.commit()
basepath = os.path.dirname(__file__)
filepath = os.path.join(basepath, r'static\uploads', fd.name)
os.remove(filepath)
flash('Item deleted.')
return redirect(url_for('sjj'))
@app.route('/cftj')
def cftj():
"""
"""
return render_template('cftj.html')
if __name__ == '__main__':
app.run(debug=True)