Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Python (http://www.programmingforums.org/forum43.html)
-   -   Running python scripts on localhost (http://www.programmingforums.org/showthread.php?t=15030)

Swan Jan 25th, 2008 5:35 AM

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 ?

Sane Jan 25th, 2008 6:02 AM

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.

Swan Jan 25th, 2008 6:11 AM

Re: Running python scripts on localhost
 
webserver means.... apache.exe ?

Infinite Recursion Jan 25th, 2008 9:30 AM

Re: Running python scripts on localhost
 
Yes. (or IIS if you are using windows).

Sane Jan 25th, 2008 11:19 AM

Re: Running python scripts on localhost
 
IR, why not use Apache for Windows?

Infinite Recursion Jan 25th, 2008 12:36 PM

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. :)

Sane Jan 25th, 2008 1:04 PM

Re: Running python scripts on localhost
 
Gotchya. As long as we're clear on that. ;)

Swan Jan 27th, 2008 10:53 PM

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.

Sane Jan 28th, 2008 12:11 AM

Re: Running python scripts on localhost
 
Quote:

Originally Posted by Swan (Post 140405)
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.

Swan Jan 30th, 2008 11:51 PM

Re: Running python scripts on localhost
 
Quote:

Originally Posted by Sane (Post 140414)
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.


All times are GMT -5. The time now is 4:44 PM.

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