0

I have the table in the web form. I will change the values from the drop down and i will submit it. I want to get all the values from table in dictionary format into post method while submitting the page. I will store those values in the backend database.

Can someone suggest me to get the table values from the form in post method python ? Am using flask for front end.

html code for table creation:

 <table>
<tr><td>LL6cdsid</td><td>resourcecdsid</td><td>workstation</td><td>location</td><td>date</td><td>status</td><td>raiseit</td><td>changestatus</td><td>Requestid</td></tr>
{%for item in requests %}
    <tr><td>{{item[0]}}</td>
    <td>{{item[1]}}</td>
    <td>{{item[2]}}</td>
    <td>{{item[3]}}</td>
    <td>{{item[4]}}</td>
    <td>{{item[5]}}</td>
    <td><a href="http://example.com/">Raise IT</a></td>
        <td><select name="status" id="status">
        <option value="RAISED">NEW</option>
        <option value="RAISED">RAISED</option>
        <option value="PENDING">PENDING</option>
        <option value="COMPLETED">COMPLETED</option>
        <option value="CLOSED">CLOSED</option>
    </td>
    <td>NIL</td>
{% endfor %}
    <td></td></tr>
</table>

Thanks a lot

enter image description here

3
  • When you submit the form, if you use POST, then you can access the data submitted on your view function with request.form Commented Sep 3, 2020 at 16:39
  • I want everything in dictionary format... Commented Sep 3, 2020 at 16:53
  • then you’ll have to do that yourself I think Commented Sep 3, 2020 at 18:31

1 Answer 1

1

Add a hidden input whose value is same as the content of each cell:

<form method="post" action="your_flask_route">
<table>
... 
</tr>
{%for item in requests %}
<tr><td><input type="hidden" name="td1" value="{{item[0]}}">{{item[0]}}</td>
...
<td><input type="hidden" name="td5" value="{{item[5]}}">{{item[5]}}</td>
<td><a href="http://example.com/">Raise IT</a></td>
...
<td>NIL</td>
{% endfor %}
<td></td></tr>
</table>
</form>

Then in flask you can get the submitted form details this way:

request.form['td1']
...
request.form['td5']
Sign up to request clarification or add additional context in comments.

2 Comments

am getting this while trying to access request.form['td1'] *** werkzeug.exceptions.HTTPException.wrap.<locals>.newcls: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. (Pdb) request.form['td1'] *** werkzeug.exceptions.HTTPException.wrap.<locals>.newcls: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. (Pdb) request.form['td2'] *** werkzeug.exceptions.HTTPException.wrap.<locals>.newcls: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. (Pdb)
html <tr><td><input type="hidden" name="td1" value="{{item[0]}}">{{item[0]}}</td> <td><input type="hidden" name="td2" value="{{item[1]}}">{{item[1]}}</td> <td><input type="hidden" name="td3" value="{{item[2]}}">{{item[2]}}</td> <td><input type="hidden" name="td4" value="{{item[3]}}">{{item[3]}}</td> <td><input type="hidden" name="td5" value="{{item[4]}}">{{item[4]}}</td> <td><input type="hidden" name="td6" value="{{item[5]}}">{{item[5]}}</td>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.