Web 服务和/或处理 GET 和 POST 的 Python 方法

发布于 2024-08-18 17:30:52 字数 366 浏览 7 评论 0原文

我使用 python 已经有一段时间了。最近我开始使用 Twisted 来学习 Sockets,这对学习 Telnet、SSH 和消息传递很有帮助。我想提出一个想法并以网络方式实现它。经过一周的搜索,我真正能做的就是创建一个可以自行处理 GET 和 POST 的资源。有人告诉我这是不好的做法。

所以一周后我的问题是:
* Tornado 和标准 Python 套接字等其他选项是否是更好(或更流行)的方法?
* 人们真的应该在 Twisted GET 和 POST 操作中使用单独的资源吗?
* 在 Python 开发这一领域开始的好资源是什么?

我的语言背景是 C、Java、HTML/DHTML/XHTML/XML,我的主要系统(甚至家庭)是 Linux。

I have been working with python for a while now. Recently I got into Sockets with Twisted which was good for learning Telnet, SSH, and Message Passing. I wanted to take an idea and implement it in a web fashion. A week of searching and all I can really do is create a resource that handles GET and POST all to itself. And this I am told is bad practice.

So The questions I have after one week:
* Are other options like Tornado and Standard Python Sockets a better (or more popular) approach?
* Should one really use separate resources in Twisted GET and POST operations?
* What is a good resource to start in this area of Python Development?

My background with languages are C, Java, HTML/DHTML/XHTML/XML and my main systems (even home) are Linux.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

安稳善良 2024-08-25 17:30:52

我建议不要构建自己的 Web 服务器并处理原始套接字调用来构建 Web 应用程序;将您的 Web 服务编写为 wsgi 应用程序并使用现有的 Web 服务器更有意义,无论是 Tornado 还是带有 mod_wsgi 的 apache。

I'd recommend against building your own web server and handling raw socket calls to build web applications; it makes much more sense to just write your web services as wsgi applications and use an existing web server, whether it's something like tornado or apache with mod_wsgi.

枯寂 2024-08-25 17:30:52

如果您所做的更多是一个网站而不是 API,请考虑使用普通的 Web 框架,例如 Django。

If what you're doing is more of a web site than an API, look into using a normal web framework like Django.

笔落惊风雨 2024-08-25 17:30:52

我将尝试逐一回答您的各个观点。

Tornado 和标准 Python 套接字等其他选项是否更好
(或更流行的)方法?

WSGI 框架是目前最流行的选择。他们可以给你
访问 GETPOST 原语,但通常用足够的语法糖包装它们
让您快速参加比赛。

几乎没有人处理 htt 的套接字。为了给您一个想法,比较流行的 http 库之一 requests最初包装 urrllib2 直到最近

真的应该在 Twisted GET 和 POST 操作中使用单独的资源吗?

我不能谈论这个,因为我不是 Twisted 开发人员。它似乎本身就是一种语言。

在 Python 开发这个领域有什么好的资源可以入手?

为了处理 GETPOSTWebob 可能是很好的起点。

对于更多上下文,webob 正在包装来自 WSGI 的基本 Python 原语(与“威士忌”押韵) 。 WSGI 是 Web 应用程序和服务器之间的接口,与 CGI 不同。

PEP 3333,如果您对 http 的本质感兴趣,定义 WSGI 标准的文档是一个非常好的起点。

在堆栈的下层,还有许多值得检查的 WSGI 服务器。云托管的平台即服务 (PaaS) 选项,例如 Google App EngineHeroku 将为您处理详细信息。另一方面,有专门的 wsgi 服务器,例如 gunicornTornado,后者您已经很熟悉了。

如果您只想完成工作,请查看 BottleFlaskDjango 或任何其他优秀的 Python Web 框架。

I'll try to answer your various points individually.

Are other options like Tornado and Standard Python Sockets a better
(or more popular) approach?

WSGI frameworks are by far the most popular options these days. They can give you
access to GET and POST primitives, but often wrap them with enough syntactic sugar
to get you off to the races quickly.

Hardly anyone deals with sockets for htt. To give you an idea, one of the more popular http libraries, requests initially wrapped urrllib2 up until recently.

Should one really use separate resources in Twisted GET and POST operations?

I can't speak to this as I'm not a Twisted developer. It seems to be a language unto itself.

What is a good resource to start in this area of Python Development?

For handling GETs and POSTs, Webob is probably a good place to start.

For some more context, webob is wrapping base Python primitives coming from WSGI (rhymes with "whiskey"). WSGI is an interface between web applications and servers, not unlike CGI.

PEP 3333, the document which defined the WSGI standard, is a really good place to start if you're interested in the nitty gritty of http.

Going a bit lower in the stack, there are also a number of WSGI servers worth checking out. Cloud-hosted, Platform-as-a-Service (PaaS) options like Google App Engine and Heroku will take care of the details for you. On the other hand, there's specialized wsgi servers like gunicorn and Tornado, the latter of which you're already familiar with.

If you are looking to just get stuff done, check out Bottle, Flask, Django, or any of the other great Python web frameworks out there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文