Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template not rendered #57

Open
zdenop opened this issue Jan 30, 2022 · 2 comments
Open

Template not rendered #57

zdenop opened this issue Jan 30, 2022 · 2 comments

Comments

@zdenop
Copy link

zdenop commented Jan 30, 2022

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 %}
@Aurilliax
Copy link

Aurilliax commented Jan 4, 2023

I'm having this exact same issue, everything appears to be configured correctly, yet my dropzone is not being rendered when placed inside of my form. It renders okay if I place it outside of the form though.

Did you find a solution?

@zdenop
Copy link
Author

zdenop commented Jan 4, 2023

I found other example that worked for me: https://bucket401.blogspot.com/2022/02/flask-drag-drop-click-select-example.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants