简体   繁体   English

如何在Web服务器中设置Python?

[英]How to set up Python in a web server?

Not exactly about programming, but I need help with this. 不完全是编程,但我需要帮助。

I'm running a development sever with WampServer. 我正在使用WampServer运行开发服务器。 I want to install Python (because I prefer to use Python over PHP), but it seems there isn't an obvious choice. 我想安装Python(因为我更喜欢使用Python而不是PHP),但似乎没有明显的选择。 I've read about mod_python and WSGI, and about how the latter is better. 我已经阅读了关于mod_python和WSGI以及后者如何更好的内容。

However, from what I gathered (I may be wrong) you have to do more low-level stuff with WSGI than with PHP. 但是,从我收集的内容(我可能是错的)你必须使用WSGI做比PHP更低级的东西。 So I researched about Django, but it seems too complex for what I want. 所以我研究了Django,但它似乎太复杂了我想要的东西。

So, what recommendations would you give to a newbie in this area? 那么,你会给这个领域的新手提出什么建议?

Again, sorry if this isn't about programming, but it's related, and this seems like a nice place to ask. 再次,对不起,如果这不是关于编程,但它是相关的,这似乎是一个不错的地方问。

Django is not a web server, but a web application framework. Django不是Web服务器,而是Web应用程序框架。

If you want a bare-bones Python webserver capable of some dynamic and some static content, have a look at CherryPy . 如果你想要一个能够提供动态和静态内容的简单的Python网络服务器,请看看CherryPy

Use mod_wsgi to embed Python in Apache. 使用mod_wsgi在Apache中嵌入Python。 It works very, very well. 它的工作非常非常好。

"However, from what I gathered (I may be wrong) you have to do more low-level stuff with WSGI than with PHP. So I researched about Django, but it seems too complex for what I want." “然而,从我收集的内容(我可能错了)你必须用WSGI做更多低级别的东西而不是PHP。所以我研究了Django,但它似乎太复杂了我想要的东西。”

  1. If you try to write your entire application as a WSGI-compliant application, directly accessed via mod_wsgi, you will reinvent the wheel. 如果您尝试将整个应用程序编写为符合WSGI的应用程序,可以通过mod_wsgi直接访问,那么您将重新发明轮子。

  2. If you try to write your application in Django, you will have stuff up and running in the space of a few hours. 如果您尝试在Django中编写应用程序,您将在几个小时内完成并运行。 Django is not "too complex" -- it's complete. Django不是“太复杂” - 它是完整的。 You don't have to use all of it, but -- for any realistic application -- you'll need most of it. 您不必全部使用它,但是 - 对于任何实际的应用程序 - 您将需要大部分内容。 In particular, the built-in admin will save you mountains of programming. 特别是,内置的管理员将为您节省大量的编程。

Werkzeug is a great little python tool (werkzeug) that works with mod_wsgi for creating simple apps that dont need database backends with CMS's, such as calculators .. They've even got a nifty screencast where they create a simple wiki in 30 minutes. Werkzeug是一个很棒的小python工具(werkzeug),它与mod_wsgi一起用于创建简单的应用程序,不需要CMS的数据库后端,例如计算器。他们甚至还有一个漂亮的截屏视频 ,他们在30分钟内创建一个简单的wiki。

You can always add something like SQLAlchemy/FormAlchemy later on if you eventually do want to have a ORM and CMS. 如果您最终想要拥有ORM和CMS,您可以随后添加类似SQLAlchemy / FormAlchemy的内容。

Avoid mod_python tho, it's got a pretty big memory footprint and it's actually a bit harder to install and set up than mod_wsgi, in my opinion. 避免使用mod_python,它有相当大的内存占用,而且在我看来,安装和设置实际上比mod_wsgi更难。

To use python with your Apache server you need to install mod_python the following links should help you out a bit. 要在您的Apache服务器上使用python,您需要安装mod_python以下链接应该可以帮助您。

If it's truly a development server you're setting up, and not a machine that will be promoted to production at some point, Django has a built-in development webserver that requires no Apache configuration. 如果它真的是你正在设置的开发服务器,而不是一台将在某个时候升级到生产的机器,Django有一个内置的开发web服务器 ,不需要Apache配置。

Your observation about the low-level work reflects some of the differences between PHP and Python. 您对低级别工作的观察反映了PHP和Python之间的一些差异。 PHP is a language designed from the start for the primary purpose of making web pages. PHP是一种从一开始就设计用于制作网页的主要目的的语言。 Python is a language. Python是一种语言。 Mod_Python and Mod_WSGI give the input to/output from that language a way to live in a web request/response environment. Mod_Python和Mod_WSGI为来自该语言的输入提供了一种生活在Web请求/响应环境中的方式。 Django adds web-aware framework conveniences. Django增加了Web感知框架的便利性。

You mention that python seems too complex for what you want, which rather begs the question: what do you want? 你提到python似乎太复杂了你想要的东西,而不是问题:你想要什么? :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM