I want to begin with the fact that I know nothing about linux, and I found a script that I would like to run on my server as a page, but when I goto the .py file it d开发者_开发百科ownloads the file!!! how am I suppose to run it?? am I suppose to use a php file and do a command to run the file?
Thanks in advance
This may be quite easy (and there's certainly no need to employ PHP here)!
Given a trivial Python script:
> cat cgi-bin/test.py
#!/usr/bin/env python
print '''Content-Type: text/html
<html>
<head>
<title>Hello from Python</title>
</head>
<body>
<h2>Hello from Python</h2>
</body>
</html>'''
You can run a simple CGI HTTP Server from the command-line using Python:
> python -m CGIHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
Then in another terminal window:
> w3m -dump http://localhost:8000/cgi-bin/test.py
Hello from Python
This is useful for testing CGI scripts on your local machine. If you want to configure a production HTTP server for serving Python content, then you're best off asking at https://webmasters.stackexchange.com/ .
This is not an easy task, especially if you are not good with Linux, but take a look at this:
http://docs.python.org/library/cgi.html#installing-your-cgi-script-on-a-unix-system
There are two paths:
The mod_wsgi plug-in will run a Python script. You need to configure Apache, and install mod_wsgi.
The CGI plug-in will run your Python, also. You need to configure Apache.
Note the common theme. You need to configure Apache. This isn't a Python question. It's an Apache question.
精彩评论