[Answered ]-Uploading multiple files in django form and function in views

1👍

Try to pass the form from the context in to the template

Change this part of your template

<form
    method="POST"
    action="{% url 'fask_question' %}"
    novalidate
    class="needs-validation"
    enctype="multipart/form-data"
  >
    {% csrf_token %}

    <div class="mb-3">
      <input
        type="file"
        class="clearablefileinput form-control-file"
        name="files"
        id="exampleFormControlFile1"
        multiple
      />
    </div>

    <div class="mb-3">
      <textarea
        class="form-control"
        id="exampleFormControlTextarea1"
        rows="8"
        placeholder="Type your question here"
        name="description"
      ></textarea>
    </div>

    <button type="submit" class="btn">Submit</button>
  </form>

To

  <form
    method="POST"
    action="{% url 'fask_question' %}"
    novalidate
    class="needs-validation"
    enctype="multipart/form-data"
  >
    {% csrf_token %}
  {{ form }}

    <button type="submit" class="btn">Submit</button>
  </form>

Leave a comment