add writte to DB
This commit is contained in:
51
app.py
51
app.py
@@ -1,47 +1,70 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from turtle import st
|
||||
from flask import Flask, render_template, request, flash, redirect, url_for
|
||||
from werkzeug.utils import secure_filename
|
||||
import os
|
||||
from models import db
|
||||
from models import PrintedDetal
|
||||
import logging
|
||||
from models import PrintedDetal
|
||||
|
||||
logging.basicConfig(filename='app.log', encoding='utf-8', level=logging.DEBUG)
|
||||
|
||||
|
||||
UPLOAD_FOLDER = 'uploads'
|
||||
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
|
||||
UPLOAD_FOLDER = 'static/img/uploads'
|
||||
UPLOAD_FOLDER2 = '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
|
||||
|
||||
db.init_app(app)
|
||||
|
||||
|
||||
def allowed_file(filename):
|
||||
return '.' in filename and \
|
||||
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
detals = PrintedDetal.query.all()
|
||||
print(detals[0].imgpath)
|
||||
logging.debug(detals[0].imgpath)
|
||||
return render_template("index.html")
|
||||
|
||||
|
||||
@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 = secure_filename(image_file.filename)
|
||||
image_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
||||
print(filename)
|
||||
filename = image_file.filename
|
||||
path_img = img_folder + filename
|
||||
|
||||
filename = secure_filename(stl_file.filename)
|
||||
stl_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
|
||||
print(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))
|
||||
|
||||
if request.form.get('isprinted') == 'on':
|
||||
isprinered = True
|
||||
else:
|
||||
isprinered = False
|
||||
|
||||
detal = PrintedDetal(imgpath=str(path_img), stlpath=str(
|
||||
path_stl), 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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user