- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10784 Articles for Python
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
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
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
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
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
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
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
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
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
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
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
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("")
![harsh manvar](https://www.tutorialspoint.com/assets/profiles/19652/profile/60_33515-1517309392.jpg)
997 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
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
901 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
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/32020/profile/60_153038-1524898298.jpg)
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
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
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