简体   繁体   English

如何使用服务器端Python开发简单的Web应用程序

[英]How to develop a simple web application with server-side Python

I am wondering how to go about implementing a web application with Python. 我想知道如何使用Python实现Web应用程序。

For example, the html pages would link to python code that would give it increased functionality and allow it to write to a database. 例如,html页面将链接到python代码,这将使其具有增强的功能并允许其写入数据库。

Kind of like how Reddit does it. 有点像Reddit如何做到的。

If you're looking for server side programming with databases and html templates etc, I think Django is great, along with Pyramid. 如果您正在寻找使用数据库和html模板等进行服务器端编程的方法,那么我认为Django和Pyramid一起很棒。 However, I use Flask ( http://flask.pocoo.org/ ) for this since it is easy to use, learn and deploy even though it may not have as much support as the before mentioned 2 framework since it's just a microframework, using the Jinja2 templating engine, including a development test server with it's own debugger. 但是,我之所以使用Flask( http://flask.pocoo.org/ ),是因为它易于使用,学习和部署,尽管它可能不像前面提到的2框架那样受支持,因为它只是一个微框架,使用Jinja2模板引擎,包括带有自己的调试器的开发测试服务器。

On the other hand, if you're going for client-side programming (ie in browser implementation ) You can look up .NET Ironpython or even Brython which uses python like javascript. 另一方面,如果要进行客户端编程(即在浏览器实现中),则可以查找.NET Ironpython甚至Brython,后者使用python之类的python。

We have never used Python for a web site without a framework. 没有框架,我们从未在网站上使用过Python。 In our case that is Django. 在我们的例子中是Django。 In other words, we do not use Python for our web sites the way Perl can be used, just having Apache run a Perl script. 换句话说,我们不会像使用Perl那样将Python用于我们的网站,而只是让Apache运行Perl脚本。

The recommendations you have received about Django are sound. 您收到的有关Django的建议是正确的。 If you go the Django route, Graham Dumpleton and the modwsgi Google group were very helpful to me. 如果您选择Django路线, Graham Dumpletonmodwsgi Google小组对我很有帮助。 I could not have gotten mod_wsgi deployed on Red Hat Enterprise 5 64-bit without Graham's help. 没有Graham的帮助,我无法将mod_wsgi部署在64位的Red Hat Enterprise 5上。

Whether you choose Django or "straight" Python, you will need to become familiar with mod_wsgi. 无论您选择Django还是“直接” Python,都需要熟悉mod_wsgi。

Good luck in quantum time, which means by now, I hope this all worked out for you. 量子时间祝你好运,这意味着到现在为止,我希望这一切对你都有帮助。

You might want to check out mod_wsgi or mod_python . 您可能要签出mod_wsgimod_python

What Is mod_wsgi? 什么是mod_wsgi?

The aim of mod_wsgi is to implement a simple to use Apache module which can host any Python application which supports the Python WSGI interface. mod_wsgi的目的是实现一个易于使用的Apache模块,该模块可以托管任何支持Python WSGI接口的Python应用程序。 The module would be suitable for use in hosting high performance production web sites, as well as your average self managed personal sites running on web hosting services. 该模块将适合用于托管高性能生产网站以及运行在Web托管服务上的一般自我管理型个人网站。

- --

Current State of Mod_Python Mod_Python的当前状态

Currently mod_python is not under active development. 目前,mod_python尚未处于积极开发中。 This does not mean that it is "dead" as some people have claimed. 这并不意味着它像某些人所说的那样是“死”的。 It smiply means that the code and the project are mature enough when very little is required to maintain it. 轻描淡写意味着,只需很少的代码和项目即可维护它们,它们就足够成熟。

这是Python网站上的好文章: http : //docs.python.org/howto/webservers.html

Plain CGI is a good starting point to learn about server side scripting, but it is an outdated technology and gets difficult to maintain after certain level of complexity. Plain CGI是学习服务器端脚本的一个很好的起点,但是它是一种过时的技术,并且在经过一定程度的复杂性之后变得难以维护。 I would think it is no longer used in industrial-grade web server anymore. 我认为它不再用于工业级Web服务器。 Plus you have to setup a web server and then install some module to interpret python script (like Apache with mod_python) just to get started. 另外,您必须先设置一个Web服务器,然后安装一些模块来解释python脚本(例如带有mod_python的Apache)以开始使用。

I had some experience with Django (https://www.djangoproject.com/) and found it fairly easy to get started with since they come with development test server. 我在Django(https://www.djangoproject.com/)上有一些经验,并且发现它们很容易入门,因为它们是与开发测试服务器一起提供的。 All you need to have is a Python interpreter + Django and you can get up-and-running quickly and worry about the deployment setup later. 您所需要的只是一个Python解释器+ Django,您可以快速启动并运行,以后再担心部署设置。 They have pretty good documentation for beginner as well. 他们也为初学者提供了很好的文档。

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

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