I want to link HTML form with an excel document such that the data entered in the form can be directly appended to the excel file. For this I used python modules openpyxl and cgi.
HTML form:
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname"><br>
<label for="age">Age:</label><br>
<input type="number" id="age" name="age"><br>
<input type="submit" value="Submit">
</form>
python code:
import openpyxl as xl
import cgi
wb = xl.load_workbook('data.xlsx')
ws= wb['Sheet1']
form = cgi.FieldStorage()
name= form.getvalue('fname')+' '+form.getvalue('lname')
age = form.getvalue('age')
ws.append([name, age])
wb.save('data.xlsx')
But when I run this HTML file on localhost, the python script itself is being displayed and the python program is not executing.
This is what I am getting when I submit the form
Update: I enabled cgi in the http request using
$ python3 -m http.server --bind localhost --cgi
Now I am getting error 501