I can't get the values from django dropzone into view

放肆的年华 提交于 2019-12-25 02:34:24

问题


I have trouble getting the django Dropzonejs values of the chosen file into django. It just creates an empty file object in the models. The problem is that I can't get the values into the model. It just creates aa blank model.

HTML:

 <form class="dropzone" action="{% url 'teacher_assignment_add_file' OBJECTID %}" method="POST">
                      {% csrf_token %}
                      <div class="fallback">
                        <input name="Assignment-File" type="file" multiple />
                      </div>
                    </form>


                    <ul class="list-group list-group-activity dropzone-previews flex-column-reverse">




                      {% for file in files %}
                      <li class="list-group-item">
                        <div class="media align-items-center">
                          <ul class="avatars">
                            <li>
                              <div class="avatar bg-primary">
                                <i class="material-icons">insert_drive_file</i>
                              </div>
                            </li>

                          </ul>
                          <div class="media-body d-flex justify-content-between align-items-center">
                            <div>
                              <a href="{% url 'file123' file %}" data-filter-by="text">{{ file }}</a>
                              <br>

                            </div>
                            <div class="dropdown">
                              <button class="btn-options" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                <i class="material-icons">more_vert</i>
                              </button>
                              <div class="dropdown-menu dropdown-menu-right">
                                <a class="dropdown-item" href="#">Download</a>
                                <a class="dropdown-item" href="#">Share</a>
                                <div class="dropdown-divider"></div>
                                <a class="dropdown-item text-danger" href="#">Delete</a>
                              </div>
                            </div>
                          </div>
                        </div>
                      </li>

                      {% endfor %}

View:

@login_required
def teacher_assignment_add_files(request, assignment_id):
  if request.method == 'POST':
    file = request.POST.get('Assignment-File')
    file = File(file=file)
    file.save()
    assignment = Assignment(id=assignment_id)
    assignment.files.add(file.id)
    return redirect('teacher-detail-assignment', id = assignment_id)

来源:https://stackoverflow.com/questions/58029052/i-cant-get-the-values-from-django-dropzone-into-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!