Found 10784 Articles for Python

How to pass Drop Down Box Data to Python CGI script?

Rajendra Dharmkar
Updated on 25-Jun-2020 21:12:50

452 Views

Passing Drop Down Box Data to CGI ProgramDrop Down Box is used when we have many options available but only one or two will be selected.Here is example HTML code for a form with one drop down box − Maths Physics The result of this code is the following form − SubmitBelow is dropdown.py script to handle input given by web browser.#!/usr/bin/python # Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form ... Read More

How to pass Text Area Data to Python CGI script?

Rajendra Dharmkar
Updated on 16-Jun-2020 12:18:43

612 Views

Passing Text Area Data to CGI ProgramTEXTAREA element is used when multiline text has to be passed to the CGI Program.Here is example HTML code for a form with a TEXTAREA box − Type your text here... The result of this code is the following form −Type your text here...  SubmitBelow is textarea.cgi script to handle input given by web browser −#!/usr/bin/python # Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields if form.getvalue('textcontent'):    text_content = form.getvalue('textcontent') else:    text_content = "Not entered" print ... Read More

How to pass Radio Button Data to Python CGI script?

Rajendra Dharmkar
Updated on 16-Jun-2020 12:16:41

799 Views

Passing Radio Button Data to CGI ProgramRadio Buttons are used when only one option is required to be selected.Here is example HTML code for a form with two radio buttons − Maths Physics The result of this code is the following form − Maths  Physics Select SubjectBelow is radiobutton.py script to handle input given by web browser for radio button −#!/usr/bin/python # Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields if form.getvalue('subject'):    subject = form.getvalue('subject') else:    subject = "Not set" print "Content-type:text/html\r\r" print ... Read More

How to pass Checkbox Data to Python CGI script?

Rajendra Dharmkar
Updated on 16-Jun-2020 12:17:52

374 Views

Passing Checkbox Data to CGI ProgramCheckboxes are used when more than one option is required to be selected.Here is example HTML code for a form with two checkboxes − Maths Physics The result of this code is the following form −Maths  Physics Select SubjectBelow is checkbox.cgi script to handle input given by web browser for checkbox button.#!/usr/bin/python # Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields if form.getvalue('maths'):    math_flag = "ON" else:    math_flag = "OFF" if form.getvalue('physics'):    physics_flag = "ON" else: ... Read More

How to process a simple form data using Python CGI script?

Arnab Chakraborty
Updated on 09-Sep-2023 23:02:23

3K+ Views

Suppose there is an HTML file as below − FirstName: LastName: After submitting this form it should go to a Python page named "getData.py", where you should fetch the data from this HTML page and show. then below is the code for Python CGI. #!C:\Python27\python.exe # Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields first_name = form.getvalue('first_name') last_name  = form.getvalue('last_name') print("Content-type:text/html") print print("") print("") print("Hello - Second CGI Program") print("") print("") print(" ... Read More

How to send the result of Python CGI script to the browser?

Arnab Chakraborty
Updated on 22-Jun-2020 15:37:06

202 Views

# Get data from fields from HTML page first_name = form.getvalue('first_name') last_name  = form.getvalue('last_name') send data to Browser print("Content-type:text/html") print print("") print("") print("Hello - Second CGI Program") print("") print("") print(" Hello %s %s " % (first_name, last_name)) print("") print("")

How to read all HTTP headers in Python CGI script?

harsh manvar
Updated on 27-Feb-2020 05:31:58

998 Views

It is possible to get a custom request header's value in an apache CGI script with python. The solution is similar to this.Apache's mod_cgi will set environment variables for each HTTP request header received, the variables set in this manner will all have an HTTP_ prefix, so for example x-client-version: 1.2.3 will be available as variable HTTP_X_CLIENT_VERSION.So, to read the above custom header just call os.environ["HTTP_X_CLIENT_VERSION"].The below script will print all HTTP_* headers and values −#!/usr/bin/env python import os print "Content-Type: text/html" print "Cache-Control: no-cache" print print "" for headername, headervalue in os.environ.iteritems():     if headername.startswith("HTTP_"):         print "{0} = {1}".format(headername, headervalue)   ... Read More

How to write Python CGI program to interact with MySQL?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:22

902 Views

suppose you want to login into you account using Python CGi script, below is the details login.html email: password: login.py #!C:\Python27\python.exe import MySQLdb import cgi import Cookie # Open database connection db = MySQLdb.connect("localhost", "root", "", "student" ) # prepare a ... Read More

How to execute Python CGI Script on Apache Server?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:22

416 Views

in apache server normally python script will not run. SO you have to go httpd.conf file in apache server, inside that you will find some .php, .asp etc in a property called AddHandler, you have to put there .py. save the file and restart the server. then run your python CGI script, it will run properly 

How to configure Apache for Python CGI Programming?

Rajendra Dharmkar
Updated on 16-Jun-2020 12:45:17

2K+ Views

Configure Apache Web server for CGITo get your server run CGI scripts properly, you have to configure your Web server. We will discuss how to configure your Apache web server to run CGI scripts.Using ScriptAliasYou may set a directory as ScriptAlias Directive (options for configuring Apache). This way, Apache understands that all the files residing within that directory are CGI scripts. This may be the most simple way to run CGI Scripts on Apache. A typical ScriptAlias line looks like following in httpd.conf file of your Apache web server.ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/So, search ScriptAlias in your httpd.conf file and uncomment the ... Read More

Advertisements