1

I am trying to implement dropzone in my project to upload multiple images. But apparently, when I call dropzone.create(action=''), I keep getting the error that the url is not build. Below are the implementation details I did.

This is my css code filename: template.html.j2

{% block style %}
{{ dropzone.load_css() }}
{{ dropzone.style('border: 2px dashed #0087F7; margin: 10%; min-height: 400px;') }}
{% endblock %}

This is the import of dropzone:

{% block scripts %}
<script src="{{url_for('static', filename='jsfiles/dropzone.js')}}"></script>
{% endblock %}

The Body part:

{{ dropzone.create(action=url_for('folder1.upload, id=user.id'))}}
{{ dropzone.load_js() }}
{{ dropzone.config() }}

This is my function : File name:user.py

@inspection.route('/users/<int:user__id>', methods=['GET', 'POST'])
def upload(id):
    //Some Code
    if form.validate_on_submit() and 'photo' in request.files:
      for f in request.files.getlist('photo'):
         filename = secure_filename(f.filename)
         print(filename)

    return render_template('folder/user_details.html.j2')

The folder structure is as below:

  • Folder1
    • user.py
  • Templates
    • template.html.j2
  • app.py

It would be great if someone can point out why I keep getting this error.

Cannot build url for endpoint folder1.upload
Harshita
  • 57
  • 8

1 Answers1

0

Try this:

Body part

{{ dropzone.create(action=url_for('folder1.user.upload, pk=user.id'))}}
{{ dropzone.load_js() }}
{{ dropzone.config() }}

user.py

@inspection.route('/users/<int:pk>', methods=['GET', 'POST'])
def upload(pk):
     //Some Code
     if form.validate_on_submit() and 'photo' in request.files:
         for f in request.files.getlist('photo'):
             filename = secure_filename(f.filename)
             print(filename)

    return render_template('folder/user_details.html.j2')
Waket Zheng
  • 5,065
  • 2
  • 17
  • 30