Python如何用于创建Web服务? [英] How Python is used to create web services?

查看:117
本文介绍了Python如何用于创建Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是使用PHP创建我的Web服务,但我有兴趣切换到Python,因为它的简单性。在我的web服务器上(我创建了一个tmp.py),只有一行:

  printHello! 

然后我在浏览器中打开这个文件。我很惊讶,它的作品(我看到你好!)。但还有两个人认为我需要知道:


  1. 如何访问get和post变量以及会话?

    / li>
  2. 如何从python使用数据库。 Python是否像PHP一样连接到MySQL服务器或使用其他方法?
  3. a href =http://docs.python.org/howto/webservers.html =nofollow> HOWTO在网络中使用Python 是这方面的官方Python手册。这是一个相当不错的起点,简要介绍了这个主题,并列出了最常见的选项:




    • CGI和CGI衍生产品(Fast CGI,WSGI)

    • mod_python
    • 完整框架,最显着的是Django


      虽然我很欣赏Python的优雅和强大,但它远非Web开发的自然或标准选择。在选择语言之前,请仔细考虑用例以及谁来维护代码。


      I always created my web services using PHP but I am interested in switching to Python because of its simplicity. On my web server (I have created a "tmp.py") just with one line:

      print "Hello!"
      

      And then I have opened this file in my browser. I was surprised that it works (I saw "Hello!"). But there are two more thinks that I need to know:

      1. How do I access the get and post variables as well as the session?
      2. How do I use databases from python. Does Python connects to MySQL server like PHP does or some other approach is used?

      解决方案

      HOWTO Use Python in the web is the official Python manual on this matter. It's a fairly good starting point, giving a brief overview on the subject, and listing the most common options:

      • CGI and CGI spin-offs (Fast CGI, WSGI)
      • mod_python
      • Full frameworks, most notably Django

      Although I admire Python for its elegance and power, it's far from being the natural or standard choice for web development. Carefully consider the use case, and who will maintain the code, before picking the language.

      这篇关于Python如何用于创建Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆