'Django template return POST array
I have an issue about returning data array in POST. I do not find a way to do it...
Here the code, I remove not necessary part of the code :
- View
def viewPro(request): if request.method == 'POST': if bool(request.FILES.get('file', False)) == True : ... if analyseType == 'r': ... elif analyseType == 'm': fc, dRect, ctrlRect = ExtractData(file, analyseType) context = { ... 'f' = True, 'fc' = fc, 'dRect': dRect, 'ctrlRect': ctrlRect, } return render(request, 'ctd.html', context) else: ... dRect = request.POST.get("dRect") ctrlRect = request.POST.get("ctrlRect") fc = request.POST.get("fc") UpdateData(fc, dRect, ctrlRect) img_out_path = executectd(..., fc, dRect, ctrlRect) context = { 'filename': img_out_path, } return render(request, 'result.html', context) else: ... (different forms) context = { 'f' = False ... } return render(request, 'ctd.html', context)
- Template
{% if factors %} <br> <div class="card"> <div class="card-body p-5"> <div class="text-center mb-5"> <h2 class="h4 fw-bolder popup"> cf </h2> <h6 class="popup"> <img src="{% static 'assets/help.jfif' %}" onclick="showContextualHelp('cf')"> <span class="popuptext" id="cf"> Fill here the cf </span> </h6> <br> <div class="container"> <div class="row gx-5 justify-content-center"> <table> <thead> <tr> </tr> </thead> <tbody> {% for key, value_list in fc.items %} <tr> <th>{{ key }}</th> {% for value in value_list %} <td><input class="form-control" value="{{ value }}" {{ value }}></td> {% endfor %} </tr> {% endfor %} </tbody> </table> </div> </div> </div> </div> </div> <br> <div id="template-multi2" style="display:none" > <div class="card"> <div class="card-body p-5"> <div class="text-center mb-5"> <h2 class="h4 fw-bolder popup"> dRect </h2> <h6 class="popup"> <img src="{% static 'assets/help.jfif' %}" onclick="showContextualHelp('d_rect')"> <span class="popuptext" id="cf"> TODO </span> </h6> <br> <div class="container"> <div class="row gx-5 justify-content-center"> <table> <thead> <tr> <th></th> <th>TODO </th> <th>TODO </th> </tr> </thead> <tbody> <tr> <th>TODO</th> <td><input class="form-control" value="{{ dRect.0 }}" {{ dRect.0 }}></td> <td><input class="form-control" value="{{ dRect.1 }}" {{ dRect.1 }}></td> </tr> <tr> <th>TODO</th> <td><input class="form-control" value="{{ dRect.2 }}" {{ dRect.2 }}></td> <td><input class="form-control" value="{{ dRect.3 }}" {{ dRect.3 }}></td> </tr> </tbody> </table> </div> </div> </div> </div> </div> <br> <div class="card"> <div class="card-body p-5"> <div class="text-center mb-5"> <h2 class="h4 fw-bolder popup"> Controle Rectangle </h2> <h6 class="popup"> <img src="{% static 'assets/help.jfif' %}" onclick="showContextualHelp('ctrl_rect')"> <span class="popuptext" id="ctrl_rect"> Fill here the location </span> </h6> <br> <div class="container"> <div class="row gx-5 justify-content-center"> <table> <thead> <tr> <th></th> <th> X coordinate</th> <th> Y coodinate</th> </tr> </thead> <tbody> <tr> <th>Min</th> <td><input class="form-control" value="{{ ctrlRect.0 }}" {{ ctrlRect.0 }}></td> <td><input class="form-control" value="{{ ctrlRect.1 }}" {{ ctrlRect.1 }}></td> </tr> <tr> <th>Max</th> <td><input class="form-control" value="{{ ctrlRect.2 }}" {{ ctrlRect.2 }}></td> <td><input class="form-control" value="{{ ctrlRect.3 }}" {{ ctrlRect.3 }}></td> </tr> </tbody> </table> </div> </div> </div> </div> </div> <br> </div> {% endif %}
In my template, I first give some information and files. Then, the same template is reload with last information and new ones as fc, dRect, ctrlRect read in a file.
These values can be modify by the user. And my problem is here. These informations are in different arrays. It is not a problem to read values and display it. But if the user modify one of these values, how can I access it in the view with POST ? These values are not in a Form, because I do not found a form structure for it. Have you any idea how I can do it ?
Thanks ;)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
