added admin page

This commit is contained in:
Александр Геннадьевич Сальный
2022-10-17 22:05:57 +03:00
parent 1808c8238f
commit cae7dc1dac
3 changed files with 140 additions and 4 deletions

40
app.py
View File

@@ -1,21 +1,53 @@
from flask import Flask, render_template
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
UPLOAD_FOLDER = 'uploads'
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////app.db'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
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)
return render_template("index.html")
@app.route("/admin", methods=['GET', 'POST'])
def admipage():
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 = secure_filename(stl_file.filename)
stl_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
print(filename)
return render_template("adminpage.html")
else:
return render_template("adminpage.html")
if __name__ == "__main__":
app.run(host="0.0.0.0", debug="True", port="3800")
app.run(host="0.0.0.0", debug="True", port="3800")