Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 25th, 2008, 5:35 AM   #1
Swan
Programmer
 
Join Date: Jan 2008
Posts: 31
Rep Power: 0 Swan is on a distinguished road
Running python scripts on localhost

I am able to run the fibonacci.py on the activepython editor. But when i try to run a python script ( say webpagecounter.py) for localhost, the browser loads the script. How should i force browser to run that script ?
Swan is offline   Reply With Quote
Old Jan 25th, 2008, 6:02 AM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: Running python scripts on localhost

Well I'm going to assume you have everything necessary set up... such as the web server, CGI support, placed the script in the appropriate directory, linked the .py extention to the cgi-handler, etc...

Then, your code should start off with something like:

#!c:/python24/python

import cgitb
import cgi
cgitb.enable()

print "Content-type: text/html\r"
print "\r"

Depending on your CRLF, and location of Python. My example is if the web server is on Windows, with the Python interpreter at c:/python24/python.exe.
Sane is offline   Reply With Quote
Old Jan 25th, 2008, 6:11 AM   #3
Swan
Programmer
 
Join Date: Jan 2008
Posts: 31
Rep Power: 0 Swan is on a distinguished road
Re: Running python scripts on localhost

webserver means.... apache.exe ?
Swan is offline   Reply With Quote
Old Jan 25th, 2008, 9:30 AM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Re: Running python scripts on localhost

Yes. (or IIS if you are using windows).
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jan 25th, 2008, 11:19 AM   #5
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: Running python scripts on localhost

IR, why not use Apache for Windows?
Sane is offline   Reply With Quote
Old Jan 25th, 2008, 12:36 PM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Re: Running python scripts on localhost

Sane... Personally, I would definitely run Apache across all supported platforms...

I guess my wording should have been more defined... I was merely pointing out that IIS was a web server option on the windows platform.

For the record, I suggest using Apache.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jan 25th, 2008, 1:04 PM   #7
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: Running python scripts on localhost

Gotchya. As long as we're clear on that.
Sane is offline   Reply With Quote
Old Jan 27th, 2008, 10:53 PM   #8
Swan
Programmer
 
Join Date: Jan 2008
Posts: 31
Rep Power: 0 Swan is on a distinguished road
Re: Running python scripts on localhost

No luck....
I tried installing python mod for xampp. And again tried running fibonacci.py in htdocs. But it again loads the whole script instead of running it.
Can anybody please figure out what is the problem. Why the browser is not able to detect the code and run it.
Swan is offline   Reply With Quote
Old Jan 28th, 2008, 12:11 AM   #9
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,886
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
Re: Running python scripts on localhost

Quote:
Originally Posted by Swan View Post
Why the browser is not able to detect the code and run it.

It has nothing to do with your browser. It has to do with a webserver which supports CGI capabilities with Python.

First, make sure you have a webserver which is operational. This can be verified by visiting localhost and making sure you can see any files placed in the document root.

Then, make sure you have Python installed.

The first thing your script should do is point to the location of the Python interpeter (see the code I posted in the first reply).

Finally, assert that you've configured your webserver to have CGI-support enabled for .py extentions. This process will vary depending on what webserver software you're using. It is well documented for Apache.
Sane is offline   Reply With Quote
Old Jan 30th, 2008, 11:51 PM   #10
Swan
Programmer
 
Join Date: Jan 2008
Posts: 31
Rep Power: 0 Swan is on a distinguished road
Re: Running python scripts on localhost

Quote:
Originally Posted by Sane View Post
It has nothing to do with your browser. It has to do with a webserver which supports CGI capabilities with Python.

First, make sure you have a webserver which is operational. This can be verified by visiting localhost and making sure you can see any files placed in the document root.

Then, make sure you have Python installed.

The first thing your script should do is point to the location of the Python interpeter (see the code I posted in the first reply).

Finally, assert that you've configured your webserver to have CGI-support enabled for .py extentions. This process will vary depending on what webserver software you're using. It is well documented for Apache.
Thanks, sane, i think it's running now. However i am not sure. As the script "first.py" i am running contains the code with print "hello world" only. Hello world is displayed successfully.
However most of the other scripts are still not running.
Can anybody please help me ( or link me to) with a crude sample script like say a web counter, so that i may ensure everything is running fine.
Swan is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
understanding scripts Special T Delphi 0 Oct 24th, 2006 8:26 PM
How to run Python scripts in a browser window titaniumdecoy Python 6 Jun 30th, 2006 2:39 AM
[tutorial] Python for programming beginners coldDeath Python 30 Dec 14th, 2005 11:35 AM
Anyone ever see an assembly program that could run python scripts? Datalisk Python 5 Oct 23rd, 2005 10:37 AM
Python - A Programmers Introduction coldDeath Python 17 Aug 19th, 2005 12:41 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:45 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC