refactoring file uploading
This commit is contained in:
37
app.py
37
app.py
@@ -12,60 +12,49 @@ from models import PrintedDetal
|
||||
logging.basicConfig(filename='app.log', encoding='utf-8', level=logging.DEBUG)
|
||||
|
||||
|
||||
UPLOAD_FOLDER = 'static/img/uploads'
|
||||
UPLOAD_FOLDER2 = 'static/stl'
|
||||
UPLOAD_IMG_FOLDER = os.path.join('static', 'img', 'uploads')
|
||||
UPLOAD_STL_FOLDER = os.path.join('static', 'stl')
|
||||
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'stl'}
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
|
||||
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
||||
app.config['UPLOAD_FOLDER2'] = UPLOAD_FOLDER2
|
||||
app.config['UPLOAD_FOLDER'] = UPLOAD_IMG_FOLDER
|
||||
app.config['UPLOAD_FOLDER2'] = UPLOAD_STL_FOLDER
|
||||
|
||||
db.init_app(app)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
print(app.config['UPLOAD_FOLDER2'])
|
||||
print(type(app.config['UPLOAD_FOLDER']))
|
||||
detals = PrintedDetal.query.all()
|
||||
logging.debug(detals[0].imgpath)
|
||||
return render_template("index.html")
|
||||
|
||||
return render_template("index.html", detals=detals)
|
||||
|
||||
|
||||
@app.route("/admin", methods=['GET', 'POST'])
|
||||
def admipage():
|
||||
|
||||
stl_folder = 'stl/'
|
||||
img_folder = 'img/uploads/'
|
||||
if request.method == 'POST':
|
||||
|
||||
image_file = request.files['images']
|
||||
stl_file = request.files['stl']
|
||||
|
||||
filename = image_file.filename
|
||||
path_img = img_folder + filename
|
||||
|
||||
logging.debug(path_img)
|
||||
|
||||
image_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
||||
|
||||
filename = stl_file.filename
|
||||
path_stl = stl_folder + filename
|
||||
stl_file.save(os.path.join(app.config['UPLOAD_FOLDER2'], filename))
|
||||
image_file.save(os.path.join(app.config['UPLOAD_FOLDER'], image_file.filename))
|
||||
stl_file.save(os.path.join(app.config['UPLOAD_FOLDER2'], stl_file.filename))
|
||||
|
||||
if request.form.get('isprinted') == 'on':
|
||||
isprinered = True
|
||||
else:
|
||||
isprinered = False
|
||||
|
||||
detal = PrintedDetal(imgpath=str(path_img), stlpath=str(
|
||||
path_stl), isprinted=isprinered)
|
||||
detal = PrintedDetal(imgpath=image_file.filename,
|
||||
stlpath=stl_file.filename,
|
||||
isprinted=isprinered)
|
||||
db.session.add(detal)
|
||||
db.session.commit()
|
||||
|
||||
logging.debug(path_img)
|
||||
logging.debug(path_stl)
|
||||
logging.debug(isprinered)
|
||||
|
||||
return render_template("adminpage.html")
|
||||
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user