当前位置:网站首页>Pecan — @expose()
Pecan — @expose()
2022-07-03 19:14:00 【Procedural ape treading on colorful auspicious clouds】
List of articles
@expose()
pecan.expose Can mark controller Method , So that this method can pass http visit .
pecan.expose The definition is as follows :
pecan.expose(template=None, generic=False, route=None, **kw)
- template: The path of the template . It can also be a renderer represented by strings , for example ‘json’.
- content_type: by template Appoint content-type
- generic:boolean value , When it comes to true when , The same path will result from http Different methods are routed to the corresponding methods .
- route: Specify the name of the path segment . The default is the function name .
Example :
hello Method will return Hello World As HTML Response body
from pecan import expose
class RootController(object):
@expose()
def hello(self):
return 'Hello World'
expose() You can use the same method multiple times .
from pecan import expose
class RootController(object):
@expose('json')
@expose('text_template.mako', content_type='text/plain')
@expose('html_template.mako')
def hello(self):
return {
'msg': 'Hello!'}
<!-- html_template.mako -->
<html>
<body>${msg}</body>
</html>
@expose(‘json’) Will use JSON Serialize the return value , The request path is /hello.json
@expose(‘text_template.mako’, content_type=‘text/plain’) Will use text_template.mako Rendering , The request path is /hello.txt
@expose(‘html_template.mako’) The request path is /hello.html, Default content-type by text/html
Specify path segments
If you want to use include - The path of , for example /some-path, But in Python in , Method names cannot contain -. At this point, you can specify expose Of route value .
Example :
Only through /some-path Path successfully accessed . and /some_path Will return 404
class RootController(object):
@pecan.expose(route='some-path')
def some_path(self):
return dict()
Routing based on request method
generic by true when , The same path can be routed to the corresponding method according to the request method .
as follows ,index Handle http GET /,index_POST Handle http POST /
expose Will generate f.when Decorator .
from pecan import expose
class RootController(object):
# HTTP GET /
@expose(generic=True, template='json')
def index(self):
return dict()
# HTTP POST /
@index.when(method='POST', template='json')
def index_POST(self, **kw):
uuid = create_something()
return dict(uuid=uuid)
边栏推荐
- Comments on flowable source code (37) asynchronous job processor
- SQL: special update operation
- The most valuable thing
- 组策略中开机脚本与登录脚本所使用的用户身份
- cipher
- Smart wax therapy machine based on STM32 and smart cloud
- Scrape crawler framework
- The earliest record
- Record: writing MySQL commands
- Streaming media server (16) -- figure out the difference between live broadcast and on-demand
猜你喜欢
![How to read the source code [debug and observe the source code]](/img/87/3cb25eb0301dc8046e39b997411e59.jpg)
How to read the source code [debug and observe the source code]
![[water quality prediction] water quality prediction based on MATLAB Fuzzy Neural Network [including Matlab source code 1923]](/img/aa/9980acc9839f067202d46faabbf029.png)
[water quality prediction] water quality prediction based on MATLAB Fuzzy Neural Network [including Matlab source code 1923]

ActiveMQ的基础

How to build an efficient information warehouse

235. 二叉搜索樹的最近公共祖先【lca模板 + 找路徑相同】

EGO Planner代码解析bspline_optimizer部分(2)

Su embedded training - Day10

Pan for in-depth understanding of the attention mechanism in CV

FBI警告:有人利用AI换脸冒充他人身份进行远程面试

The necessity of lean production and management in sheet metal industry
随机推荐
The installation path cannot be selected when installing MySQL 8.0.23
Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification
Record: MySQL changes the time zone
Record the errors reported when running fluent in the simulator
FBI warning: some people use AI to disguise themselves as others for remote interview
Simple solution of physical backup and restore of Damon database
Foundation of ActiveMQ
Think of new ways
C enum contains value - C enum contains value
High concurrency Architecture - distributed search engine (ES)
During MySQL installation, the download interface is empty, and the components to be downloaded are not displayed. MySQL installer 8.0.28.0 download interface is empty solution
[wallpaper] (commercially available) 70 wallpaper HD free
变化是永恒的主题
Valentine's Day - make an exclusive digital collection for your lover
[proteus simulation] a simple encrypted electronic password lock designed with 24C04 and 1602LCD
High concurrency architecture cache
OSPF - detailed explanation of stub area and full stub area
How does if ($variable) work? [repeat] - how exactly does if ($variable) work? [duplicate]
Record: pymysql is used in pycharm to connect to the database
__ Weak and__ The difference between blocks