Python Forum
trying to use cgi to get html form data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trying to use cgi to get html form data
#1
Hello,
I have made an HTML form and need to get the data that a user inputs into an excel sheet.
Looking around, i found that it could be possible with cgi.
I installed XAMPP and modified the httpd.conf file accordingly.
When i run a test.py file which outputs to the browser, it works.

But, when i try to send data from my form to the program (and i want to use openpyxl to then put it in excel sheet), the program doesnt run.
Instead, it prints the code from the .py file in the browser.

I've been at this for sometime now..i uninstalled and re-installed XAMMP thinking i might have made some bad changes somewhere, but no success.

It is a fairly lengthy form, which uses text fields, textareas, date, radio buttons and drop down menus.

This is the line from the html file where i specify the .py file to run.
<form name='History' action='file:///C:/xampp/cgi-bin/test.py' method='POST'>

This is the code that i want to run when i hit the submit button.
#!C:\Users\Daucus\AppData\Local\Programs\Python\Python37-32\python.exe

import cgi, openpyxl

form = cgi.FieldStorage()
PatientID =  form.getvalue('pid')

wb = openpyxl.load_workbook('Book1.xlsx')
sheet = wb['Sheet1']

sheet.cell(1,1).value = PatientID

wb.save('Book1.xlsx')
But it just prints this same thing as output.
Any help will be highly appreciated.
Thanks!
Reply


Messages In This Thread
trying to use cgi to get html form data - by test - Jun-24-2019, 05:45 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020