开发者

How to run python scripts?

开发者 https://www.devze.com 2023-03-22 08:04 出处:网络
I am a PHP developer and am I want to use python for a project. What is the most common and simplest way to run python scr开发者_StackOverflowipt on a server like apache or lighttpd? I am having troub

I am a PHP developer and am I want to use python for a project. What is the most common and simplest way to run python scr开发者_StackOverflowipt on a server like apache or lighttpd? I am having trouble understanding how server languages that are not PHP or ASP run on servers.


In Python we have something called WSGI. But I believe this is too much for you right now. Grab a Python web framework, like Django. It comes with a web server and with good documentation on how to deploy it later. Play with it and things will start to clear up.


The longer version is that Python is a general purpose language - it's not designed for the web like PHP is. So you need a bit of work the get it to do web stuff and we already have some good frameworks for that (Django is the easiest to start with, so that is why I'm recommending it to you).

In general you should understand how the web works. It uses HTTP as a protocol for communication, which is build on top of the TCP stack, so a web application is just a server, that uses sockets (PHP has them as well as Python) and understands HTTP. Python comes with one build in - the SimpleHTTPServer, but it is not very good for production uses (it's great for development, though). This is why there are things like mod_wsgi (Python specific), FastCGI (general purpouse). Those things are basically ways for a real, production grade, web server (Apache, nginx) to talk to our python app and feed it the HTTP they get.


You can install gunicorn a Pure Python WSGI HTTP Server for UNIX. http://gunicorn.org/.


Typically, Apache is used with mod_python. See this mod_python tutorial

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号