-
Notifications
You must be signed in to change notification settings - Fork 66
Open
Description
Hello,
I tried to make single-page app with dropzone but my template is not rendered. Without dropzone, it works, so I believe I miss configurations. Here is simplified example:
app.py:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import pathlib
from flask import Flask, render_template, request
from flask_dropzone import Dropzone
app = Flask(__name__)
basedir = pathlib.Path(__file__).parent
app.config.update(
UPLOADED_PATH=pathlib.Path(basedir, "uploads"),
)
dropzone = Dropzone(app)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/", methods=["POST", "GET"])
def upload():
if request.method == "POST":
f = request.files.get("file")
if f.filename != "":
f.save(pathlib.Path(app.config["UPLOADED_PATH"], f.filename))
result = f"{f.filename} uploaded!"
print(result)
return render_template("result.html", message=result)
return render_template("index.html")
if __name__ == "__main__":
app.run(debug=True)index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Flask-Dropzone Demo</title>
{{ dropzone.load_css() }}
{{ dropzone.style('border: 2px dashed #0087F7; margin: 10%; min-height: 400px;') }}
</head>
<body>
{{ dropzone.create('upload') }}
<!-- This works -->
<!--
<form method="POST" action="" enctype="multipart/form-data"><div>
<input type="file" name="file" id="inputFile01" style="max-width:700px;">
<button type="submit" value="Submit" id="submitfile">Submit</button>
</div></form>
-->
{% block content %}{% endblock %}
{{ dropzone.load_js() }}
{{ dropzone.config() }}
</body>
</html>result.html:
{% extends "index.html" %}
{% block content %}
<h1>Result</h1>
<p>{{ message }}</p>
{% endblock %}Metadata
Metadata
Assignees
Labels
No labels