2

I'm trying to upload an Excel file automatically with Dropzone but it's not happening.

HTML:

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<title>Auditoria - SAE</title>

<link href="{% static 'css/style.css' %}" rel="stylesheet">
<link rel="stylesheet" href="https://rawgit.com/enyo/dropzone/master/dist/dropzone.css">

</head>
<body>
<div class="container">
        <form action="{% url 'auditoria_app:index' %}" class="dropzone">
            {% csrf_token %}
            <div class="fallback">
              <input name="file" type="file" />
            </div>
        </form>


    <script src="https://rawgit.com/enyo/dropzone/master/dist/dropzone.js"></script>

</div>

</body>
</html>

My view:

def index(request):
if 'GET' == request.method:
    return render(request, 'auditoria_app/index.html')
else:
    excel_file = request.FILES["file"]

    wb = openpyxl.load_workbook(excel_file, data_only=True)
    wb.security.workbook_password = 'Rnip*2020'

    inputsCombo = wb['Inputs COMBO']
    inputsDNCombo = wb['Inputs DN COMBO']
    outputCombo = wb['OutPut COMBO']
    faixas = wb['Faixas']

    wb2 = openpyxl.load_workbook('media/sigma.xlsx', data_only=True)
    sigma = wb2['sigma']
    sic = wb2['Performance']

    numeroIbms = inputsCombo['F5'].value
    ibms = []

    output = outputResults(numeroIbms, outputCombo)

    for i in range(8, 8 + numeroIbms):
        ibm = Ibm(i, inputsCombo, inputsDNCombo, outputCombo, faixas, sigma)
        ibms.append(ibm)

    return render(request, 'auditoria_app/index.html',
                  {'ibms': ibms,
                   'numeroIbms': numeroIbms,
                   'output': output,
                   })

Important: I don't want to save the file inside the Django server, so my intention is only to read the data inside the Excel.

The file seems to load correctly in the web but the page is not being 'refreshed' after the file is ready to go to Django server! I think it might be something with the render inside the view.py.

I can retry the Excel data inside the view.py, so the file is uploaded correctly. But the page should be reloaded to carry the new template.

Thank you!

Felipe Dourado
  • 441
  • 2
  • 12

0 Answers0