Dear greyli,
Thanks for your previous help in the previous issue #43
I meet another difficult problem, I found if I want to get the input "title" and "description" from html, I must set the "<form> </form>". And Your tutorial supplies a good way: https://github.com/greyli/flask-dropzone/blob/master/examples/in-form/app.py
I have a similar problem like the previous issue I asked. How do I send local variable "r" into the route "./form"? If the local variable "r" can be sent to "hand_form", I can get "title", "description" and return a new page. Please see the below code:
@app.route('/upload', methods=['POST'])
def handle_upload():
for key, f in request.files.items():
if key.startswith('file'):
f.save(os.path.join(app.config['UPLOADED_PATH'], f.filename))
r = dealFileFunction()
return '', 204
@app.route('/form/<r>', methods=['POST'])
def handle_form(r):
title = request.form.get('title')
description = request.form.get('description')
t = database().extract("r")
return render_template('another.html', title=title, description=description, r=r, t=t)
I have checked the HTML in https://github.com/greyli/flask-dropzone/blob/master/examples/in-form/templates/index.html
See below code:
<form action="{{ url_for('handle_form') }}" enctype="multipart/form-data" method="post">
<label for="title">Title</label>
<input type="text" id="title" name="title"/><br>
<label for="description">Description</label>
<input type="text" id="description" name="description"/><br>
{{ dropzone.create() }}
<input type="submit" id="submit" value="Submit and Upload">
</form>
{{ dropzone.load_js() }}
{{ dropzone.config() }}
It seems the action will return the "handle_form" directly when the uploaded job is complete. I also try the previous method:
{{ dropzone.config(custom_options="success: function(file, response){ window.location.href = '/handle_form/' + response.message; }") }}
And I also found "document.form.action=" can modify form action property. But both of two methods are failed. If it can be done like the previous way, the webserver can not only sends a local variable to return a new page, but also get "title" and "description" at same time.
Do you have a good idea to solve it?
Thanks for your warming answer.
@greyli