473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Running Python in Browser

Chittaranjan
Hi All,

I am new to Python. I am not able to get the python script run in the browser. I am using IIS as my webserver and my python version is Python-2.4. I am under Windows-XP OS. I have done one my directories to be a virtual directory to run in my web browser. I have written some sample codes as follows

- form.html
Expand|Select|Wrap|Line Numbers
  1. <html><body>
  2. <form method="get" action="process_form.py">
  3. Name: <input type="text" name="name">
  4. <input type="submit" value="Submit">
  5. </form>
  6. </body></html>
  7.  
This is a simple HTML form from where I am posting the data to a python file. The python code as below:

- process_form.py
Expand|Select|Wrap|Line Numbers
  1. #!c:\Python24\python.exe
  2. import cgi
  3. form = cgi.FieldStorage() # instantiate only once!
  4. name = form.getfirst('name', 'empty')
  5.  
  6. # Avoid script injection escaping the user input
  7. name = cgi.escape(name)
  8.  
  9. print """\
  10. Content-Type: text/html\n
  11. <html><body>
  12. <p>The submitted name was "%s"</p>
  13. </body></html>
  14. """ % name
  15.  
When I am trying to run in the browser it show me the form but aftre entering the data in the form field and submitting it just shows up the python code in the next page like below:

#!c:\Python24\python.exe import cgi form = cgi.FieldStorage() # instantiate only once! name = form.getfirst('name', 'empty') # Avoid script injection escaping the user input name = cgi.escape(name) print """\ Content-Type: text/html\n
The submitted name was "%s"

""" % name


So please suggest me what I need to do to execute a python code from a browser what is the mistake I have done here?

Thanks and Regards,
Chittarajan :)
Jul 12 '07 #1
7 6524
bartonc
6,596 Expert 4TB
Looking at the book, Learning Python, page 386, it looks OK to me. Ensure that the hash-bang (#!) is on the first line of the module.
Jul 12 '07 #2
Thanks Sir,

I do not have the book with me and I have ordered the book. But if any kind of other help will be highly appreciated.

Regards,
Chittaranjan :)
Jul 12 '07 #3
bartonc
6,596 Expert 4TB
Thanks Sir,

I do not have the book with me and I have ordered the book. But if any kind of other help will be highly appreciated.

Regards,
Chittaranjan :)
Ensure that the hash-bang (#!) is on the very first line of the module.
Jul 12 '07 #4
Motoma
3,237 Expert 2GB
It sounds like the python file is not set up to be executed by your webserver. Read through Microsoft's documentation on getting Python scripts to run with IIS.
Jul 12 '07 #5
It sounds like the python file is not set up to be executed by your webserver. Read through Microsoft's documentation on getting Python scripts to run with IIS.
Thanks Motoma,

This was really helpful. I have tried and able to setup and browse the python files in browser. But can you please let me know some helpful sites for pymssql installation and examples by which I can move forward to link with database in my coding.

Regards,
Chittaranjan :)
Jul 17 '07 #6
Motoma
3,237 Expert 2GB
Thanks Motoma,

This was really helpful. I have tried and able to setup and browse the python files in browser. But can you please let me know some helpful sites for pymssql installation and examples by which I can move forward to link with database in my coding.

Regards,
Chittaranjan :)
Forgive me if this sounds obtuse, but have you read pymssql's documentation?
Jul 17 '07 #7
Chittaranjan,

Is your problem solved?
If so, can you please let me know how to run a python file (for eg, test.py) on the browser?
I tried running the file in Django, like http://localhost:8000/demo/test.py but getting File Not Found (404) error.

Please help me

Thanks
Ravi K
Jan 27 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Rolfe | last post by:
Hi, I struggled, and got mod_python running on Apache/Win2k. Follow these instructions verbatim and you shouldn't have any trouble. These instructions are based on...
3
by: Sean Berry | last post by:
I have a python program that I want to be able to run from a browser window. It gets run in a cron job every day, but I want my boss to be able to run it whenever he wants to since the database...
2
by: Lad | last post by:
I would like to use httplib/urllib to download webpages from 3 different websites.From my script I want to open 3 webbrowser windows( 3 threads) and open in each thread( window) pages from a...
1
by: qwejohn | last post by:
Hello, I had posted this question in the twisted mailing list but did not got a solution ; I hope that the python Gurus of this forum can help me a bit. I am trying the exmaple in the python...
5
by: merry.sailor | last post by:
Hello, I am using python and CGI to initiate a long running simulation (up to 5h long) on a remote machine. The main idea is that I use a form, enter the parameters and a CGI scripts start the...
1
by: Warren | last post by:
I am running win2k pro and was wondering if writing python scripts or running modules dumps anything in the "C" drive? I have 3 partitions and run python on the 3rd one or "E"drive. My "C" drive...
0
by: Mathias K. | last post by:
Hello everyone! I just installed Python 2.5 and i want to use Python to build websites. I could load mod_python successfully with Apache but i fail to let the .py-files to be executed! In...
8
SimonJ621
by: SimonJ621 | last post by:
Hi all, I have an python application that I would like to use to send some data to a web page. I am sending this data via url encoding to pass some variables to the page. While I can get the...
3
by: sophie_newbie | last post by:
Hi, I have a cgi script that performs a very long computation that can take several hours to complete. Is there any smart way that I can keep this script running until it is finished (after the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.