windows 为本地 Web 应用程序推荐的 Python 库/框架?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4543604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Recommended python library/framework for local web app?
提问by Jonathan Eunice
I want to create a simple LOCAL web app in Python.
我想用 Python 创建一个简单的 LOCAL Web 应用程序。
The web server and "back-end" code will run on the same system (initially, Windows system) as the UI. I doubt it matters, but the UI will be a typical webish combo of Google Chrome, HTML, CSS, JavaScript, and jQuery.
Web 服务器和“后端”代码将在与 UI 相同的系统(最初是 Windows 系统)上运行。我怀疑这是否重要,但 UI 将是 Google Chrome、HTML、CSS、JavaScript 和 jQuery 的典型网络组合。
There are a TON of Python-based web programming frameworks, but they all seem designed for building sophisticated, large-scale apps with lots of back-end infrastructure. I want the opposite: Something very simple, lightweight, and easily self-contained--just enough web server and framework to create/support a local web app.
有大量基于 Python 的 Web 编程框架,但它们似乎都是为构建具有大量后端基础设施的复杂的大型应用程序而设计的。我想要相反的东西:一些非常简单、轻量级且易于自包含的东西——只需足够的 Web 服务器和框架来创建/支持本地 Web 应用程序。
Suggestions?
建议?
回答by Anthony
I think web2pymight be a geat solution here. It requires no installation and has no dependencies (it even comes with its own Python interpreter as well as a web-server and the SQLite database). You can even distribute your application as a Windows or Mac binary(including web2py), and users can easily run it locally with no installation.
我认为web2py在这里可能是一个很好的解决方案。它不需要安装,也没有依赖项(它甚至带有自己的 Python 解释器以及 Web 服务器和 SQLite 数据库)。您甚至可以将您的应用程序作为 Windows 或 Mac 二进制文件(包括 web2py)分发,用户无需安装即可在本地轻松运行它。
回答by EinLama
Bottleis a very lightweight micro-framework. It comes as a single .py-file with no external dependencies, supports routing, a small template-engine and comes with an integrated webserver. It is easy to use and slim.
Bottle是一个非常轻量级的微框架。它是一个没有外部依赖的单一 .py 文件,支持路由,一个小的模板引擎,并带有一个集成的网络服务器。它易于使用且纤薄。
This sounds like a perfect match to your requirements :)
这听起来完全符合您的要求:)
回答by Greg Hewgill
I've used BaseHTTPServer
for this purpose. It's a web server built in to the Python standard library, and lets you have full control over the content you deliver.
我已经用于BaseHTTPServer
这个目的。它是一个内置于 Python 标准库的 Web 服务器,让您可以完全控制您提供的内容。
Since it's part of Python's standard library, you don't have to worry about any platform-specific configuration. I've used the same local server script on a Windows, Linux, and Mac OS X system without modification.
由于它是 Python 标准库的一部分,因此您不必担心任何特定于平台的配置。我在 Windows、Linux 和 Mac OS X 系统上使用了相同的本地服务器脚本,没有进行修改。
A sample bit of code might be:
示例代码可能是:
import BaseHTTPServer
class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write("Hello world!")
server_address = ('', 8080)
httpd = BaseHTTPServer.HTTPServer(server_address, Handler)
httpd.serve_forever()
回答by Jonathan Eunice
I have written a handful of such "local web server" apps since I asked this question. I don't have a final "which framework is best" answer, but I do have some insights:
自从我问这个问题以来,我已经编写了一些这样的“本地网络服务器”应用程序。我没有最终的“哪个框架最好”的答案,但我确实有一些见解:
- A simple or micro-framework is indeed a good choice.
- I've tried CherryPy and Flask frameworks. Flask is the clear winner for simplicity, with basic "set up some AJAX serving pages" functions entirely trivial to write in Flask. CherryPy documentation is often opaque, and its setup complexity notably higher.
- I'm happy with Flask, but I continue to look around. I would especially like to try Bottle, which I've seen reviewed very highly, including in other StackOverflow discussions and this side-by-side comparison: http://www.slideshare.net/r1chardj0n3s/web-microframework-battleweb2py also looks worth a try.
- 一个简单的或微框架确实是一个不错的选择。
- 我试过 CherryPy 和 Flask 框架。Flask 显然是简单性的赢家,基本的“设置一些 AJAX 服务页面”功能在 Flask 中编写完全微不足道。CherryPy 文档通常是不透明的,其设置复杂性明显更高。
- 我对 Flask 很满意,但我继续环顾四周。我特别想尝试 Bottle,我看到它的评价非常高,包括在其他 StackOverflow 讨论和并排比较中:http://www.slideshare.net/r1chardj0n3s/web-microframework-battle web2py 也看起来值得一试。
回答by Don O'Donnell
I have no direct experience but I've heard some good things about web2py:
我没有直接的经验,但我听说过一些关于 web2py 的好消息:
回答by gimel
A very simple server in the standard library is wsgiref.simple_server
.
标准库中一个非常简单的服务器是wsgiref.simple_server
.
The example looks trivial (demo_app
is also part of the module):
该示例看起来微不足道(demo_app
也是模块的一部分):
from wsgiref.simple_server import make_server, demo_app
httpd = make_server('', 8000, demo_app)
print("Serving HTTP on port 8000...")
# Respond to requests until process is killed
httpd.serve_forever()
回答by kakarukeys
chances are, you want an admin interface for basic CRUD operations on some database tables. Then Django is your best choice.
很有可能,您需要一个管理界面,用于对某些数据库表进行基本的 CRUD 操作。那么Django是你最好的选择。
回答by Lennart Regebro
Any framework will do this. Django certainly will do, but since you want something smaller, I'd recommend will BFG/Pyramid, which is very lightweight, extremely extensible and flexible and fun to use. But there are loads of others, and as mentioned, the built in wsgiref is as lightweight as you get. :-)
任何框架都会这样做。Django 肯定会做,但因为你想要更小的东西,我推荐 BFG/Pyramid,它非常轻量级,非常可扩展,灵活且使用起来很有趣。但是还有很多其他的,正如前面提到的,内置的 wsgiref 和你得到的一样轻量级。:-)
回答by atx
Pylons is extremely easy to use once you get some simple configuration set up, you'll have to have a good idea of what you want though.
一旦您设置了一些简单的配置,Pylons 就非常容易使用,但是您必须对自己想要什么有一个很好的了解。
回答by Eli Bendersky
Django comes with a built-in web server that allows you to fully test your application locally (via localhost:8080
or something of the sort). As a matter of fact, I've used it more than once to run a complete web-application locally prior to deploying it to a server. I see no reason you can't use it for your own local web-app purposes. Although it may seem that Django is big and complex, this solution is self-contained and simple to run:
Django 带有一个内置的 Web 服务器,它允许您在本地(通过localhost:8080
或类似的方式)完全测试您的应用程序。事实上,在将其部署到服务器之前,我已经不止一次使用它在本地运行完整的 Web 应用程序。我看不出有什么理由不能将它用于您自己的本地网络应用程序。尽管 Django 看起来庞大而复杂,但这个解决方案是独立的且易于运行:
- Install Django
- Go through the great tutorial, which very soon shows you how to run the web-server
- Write your code
- 安装 Django
- 通过很棒的教程,它很快就会向您展示如何运行网络服务器
- 写你的代码
That's about it. Deploying it to other machines is also simple to do, especially with something like virtualenv
.
就是这样。将它部署到其他机器也很简单,尤其是像virtualenv
.
If you don't want a large web-framework at all, I'll have to join Greg's advice to use BaseHTTPServer
. I've used it before for specialized local applications and it's working well, doing what's expected from it and not much more. It's a very flexible solution allowing you to build something quite custom if you need it.
如果您根本不想要大型网络框架,我将不得不加入 Greg 的建议以使用BaseHTTPServer
. 我之前曾将它用于专门的本地应用程序,并且运行良好,可以完成预期的工作,仅此而已。这是一个非常灵活的解决方案,允许您在需要时构建非常自定义的东西。