Using Python Flask #2340
Answered
by
yudin-s
RanaUniverse
asked this question in
Q&A
Using Python Flask
#2340
|
i am very new in web dev, i don't know much js and css. So i not understand how this things works, but i am using Flask & Jinja to make templates directly so i don't understand proper way to use this in my flask apps. Please have some idea to use this? |
Answered by
yudin-s
May 19, 2026
Replies: 1 comment 1 reply
|
You do not need to put Dropzone on every page unless many pages use upload forms. The simple rule is:
In Flask/Jinja, a common pattern is to have optional blocks in <!-- base.html -->
<head>
{% block styles %}{% endblock %}
</head>
<body>
{% block content %}{% endblock %}
{% block scripts %}{% endblock %}
</body>Then on the upload page: {% block styles %}
<link rel="stylesheet" href="https://unpkg.com/dropzone@6/dist/dropzone.css">
{% endblock %}
{% block content %}
<form action="{{ url_for('upload') }}" class="dropzone" id="upload-zone"></form>
{% endblock %}
{% block scripts %}
<script src="https://unpkg.com/dropzone@6/dist/dropzone-min.js"></script>
<script>
Dropzone.autoDiscover = false;
new Dropzone("#upload-zone", {
paramName: "file",
maxFilesize: 10
});
</script>
{% endblock %}And in Flask: @app.post("/upload")
def upload():
file = request.files["file"]
file.save(os.path.join(app.config["UPLOAD_FOLDER"], file.filename))
return {"ok": True}The important part is that the |
1 reply
Answer selected by
RanaUniverse
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You do not need to put Dropzone on every page unless many pages use upload forms.
The simple rule is:
In Flask/Jinja, a common pattern is to have optional blocks in
base.html:Then on the upload page:
{% block styles %} <link rel="stylesheet" href="https://unpkg.com/dropzone@6/dist/dropzone.css"> {% endblock %}…