Pecan官方文档解读
- Introduce to pecan
- What is pecan?
- What are its characteristics?
- Create the first pecan application
- Run the pecan application
- Pecan configuration file
- Entry to the application
- Controllers and Routing
- Pecan’s Routing Algorithm
- Interacting with the Request and Response Object
- Templating in Pecan
- Writing RESTful Web Services
- Security and Authentication
- Pecan Hooks
- JSON Serialization
- Context/Thread-Locals vs. Explicit Argument Passing
- Command Line Pecan
- Logging & Testing
- Developing locally & Deploying in Production
- References
Introduce to pecan
What is pecan?
Pecan was created to fill a void in the Python web-framework world – a very lightweight framework that provides object-dispatch style routing. Pecan does not aim to be a “full stack” framework, and therefore includes no out of the box support for things like sessions or databases. Pecan instead focuses on HTTP itself.
What are its characteristics?
Although it is lightweight, Pecan does offer an extensive feature set for building HTTP-based applications, including:
Object-dispatch for easy routing
- Full support for REST-style controllers
- Extensible security framework
- Extensible template language support
- Extensible JSON support
- Easy Python-based configuration
While Pecan doesn’t provide support for sessions or databases out of the box, tutorials are included for integrating these yourself in just a few lines of code.
https://pecan.readthedocs.io/en/latest/index.html
Create the first pecan application
Run the pecan application
Pecan configuration file
Entry to the application
The Root Controller is the entry point for your application. You can think of it as being analogous to your application’s root URL path (in our case, http://localhost:8080/).
Controllers and Routing
Pecan’s Routing Algorithm
Interacting with the Request and Response Object
Templating in Pecan
Writing RESTful Web Services
with Generic Controllers
Pecan simplifies RESTful web services by providing a way to overload URLs based on the request method. For most API’s, the use of generic controller definitions give you everything you need to build out robust RESTful interfaces (and is the recommended approach to writing RESTful web services in pecan).
With RestController
TurboGears 2 is built on top of the experience of several next generation web frameworks including TurboGears 1 (of course), Django, and Rails.
Security and Authentication
Pecan Hooks
JSON Serialization
Context/Thread-Locals vs. Explicit Argument Passing
Command Line Pecan
Logging & Testing
Logging
Testing
- Tests can live anywhere in your Pecan project as long as the test runner can discover them.
- In particular, Pecan projects are known to work well with nose, pytest, and tox.
- Writing Functional Tests with WebTest
Developing locally & Deploying in Production
Developing Locally
Deploying
WSGI是一个Python标准,它描述了服务器和应用程序之间的标准接口。任何Pecan应用程序也被称为“WSGI应用程序”,因为它实现了WSGI接口,所以任何与WSGI兼容的服务器都可以用来服务于您的应用程序。
- mod wsgi是一个流行的Apache模块,可以用来托管任何与wsgi兼容的Python应用程序(包括Pecan应用程序)。
- uwsgi是一个用纯C编写的快速、自我修复和开发人员/系统管理员友好的应用程序容器服务器。
- Gunicorn或“greenunicorn”是一个用于UNIX的wsgihttp服务器。它是从Ruby的Unicorn项目移植的fork-worker前的模型。它支持eventlet和greenlet。
- cherrypy提供了一个纯pythonhttp/1.1兼容的WSGI线程池web服务器。
References
- https://pecan.readthedocs.io/en/latest/