471,349 Members | 1,247 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,349 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 6430
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

Post your reply

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

Similar topics

1 post views Thread by Rolfe | last post: by
3 posts views Thread by Sean Berry | last post: by
5 posts views Thread by merry.sailor | last post: by
reply views Thread by Mathias K. | last post: by
3 posts views Thread by sophie_newbie | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.