472,954 Members | 2,292 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 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 6506
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.