Faculty of Engineering and Mathematical Sciences 
Not logged in (login)


This forum is provided to promote discussion amongst students enrolled in Agile Web Development (CITS3403).
RSS cloud
Jump to:

project 2 - flask forms

1 of 419 articles shown, currently no other people reading this forum.
From: Timothy F.
Date: Tue 12th May 2020, 10:05am



> Hi there, 
> I have added the questions for a particular quiz to the fill out quiz html page like this:
> <tbody>
>     {% for questions in question_row %}
>     <tr>
>         <td>
>             <div class="form-group">
>             <label id={{questions.question}} name=thisQuiz>{{questions.question}}</label>
>             </div>
>         </td>
>         <td>
>             {{form.answer}}
>         </td>
>     {% endfor %}
>     </tr>
> </tbody>   
> </table>
> <div class="form-group" style="text-align: center;">
>     {{ form.submit(class="btn btn-secondary ml-3") }}
> The answers table in the db is set up so that each row represents an answer for a 
> particular question for a particular student.
> Is there a way for me to loop through the form answers in the controller, so that on submit 
> i can add multiple rows of data to the answers table, so that I can add each answer to each 
> question for the student filling out the quiz to the db.
> Very sorry if this doesn't make sense 
> Thank you

Like Haolin said, AJAX with a REST API is a neat way to solve this problem. We'll cover that 
in this weeks lecture.

However, if you want to use WTForms, there's no problem defining a form with an array of 
fields. You could even define a class of for a set of question-answer fields and access these 
using Jinja in the usual way.


Related articles

project 2 - flask forms (all 3) RSS
├─ original   Mon 11th May 2020, 11:51am, ANONYMOUS
├─ reply 1   Mon 11th May 2020, 10:39pm, Haolin W.
└─ THIS   Tue 12th May 2020, 10:05am, Timothy F.
This Page

Program written by: [email protected]
Feedback welcome
Last modified: 11:27am Sep 21 2020