문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top