def book_create(): if request.method == "GET": return render_template("book/create.html") validator = Book.get_input_validator() try: args = parser.parse(validator, request) except Exception as e: return render_template("book/create.html", error=str(e.data["exc"].arg_name)) book = Book() book.author = args["author"] book.name = args["name"] book.year = args["year"] # file file = request.files["file"] extension = file.filename.split(".")[-1] or "" book.file = book.id + "." + extension file.save(os.path.join(app.config["UPLOAD_FOLDER"], book.file)) # book.added_by_login = current_user.login book.save() return redirect(url_for("main"))