Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 trying to use cgi to get html form data
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 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/' method='POST'>

This is the code that i want to run when i hit the submit button.

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'Book1.xlsx')
But it just prints this same thing as output.
Any help will be highly appreciated.
Tool like CGi,XAMPP are really not used in Python anymore.
CGI will be removed in future Python versions.

A little history Why is WSGI necessary.
The modern way to do similar stuff to CGI,is to use eg Flask.
Can make quick demo if needed of open/save a excel file in openpyxl using Flask.
noisefloor likes this post
Thanks @Snippsat :)

However, this program is intended for a html form which i will be filling myself on my own computer. Also, i was running short on time, and so i decided to stick with cgi only.

Somehow, replacing the exact path of the .py file with http://localhost/ solved my issue.
Thanks :)

Quote: Looking around, i found that it could be possible with cgi.
Outdated for at least ten years, as already explained above.

Quote:Also, i was running short on time, and so i decided to stick with cgi only.
Wrong decision for sure. CGI is, compared to WSGI and frameworks like Flask, super complicated and it's easy to make mistakes. With Flask, it is so much easier and faster.
Except this, nobody will seriously give you any support for Python CGI questions because it is outdated dead.

So do yourself a favor, throw away your CGI-based program and re-write using a WSGI framework. The positive side effect: you can throw away the XAMPP stack as well.

Regards, noisefloor

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)