当前位置:网站首页>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)
边栏推荐
- Record the errors reported when running fluent in the simulator
- HOW TO WRITE A DAILY LAB NOTE?
- High concurrency Architecture - read write separation
- The way to treat feelings
- Add control at the top of compose lazycolumn
- Max of PHP FPM_ Some misunderstandings of children
- C enum contains value - C enum contains value
- Analyse du Code du planificateur ego bspline Section Optimizer (1)
- Record: writing MySQL commands
- High concurrency Architecture - separate databases and tables
猜你喜欢

【光学】基于matlab涡旋光产生【含Matlab源码 1927期】

Yolov3 network model building
![[leetcode] [SQL] notes](/img/8d/160a03b9176b8ccd8d52f59d4bb47f.png)
[leetcode] [SQL] notes

Does SQL always report foreign key errors when creating tables?

Using the visualization results, click to appear the corresponding sentence
![Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]. StandardContext](/img/56/ea61359dd149a49589ba7ad70812a0.jpg)
Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]. StandardContext

2022.2.14 Li Kou - daily question - single element in an ordered array

application

Su embedded training - Day10

The necessity of lean production and management in sheet metal industry
随机推荐
[optics] vortex generation based on MATLAB [including Matlab source code 1927]
The more you talk, the more your stupidity will be exposed.
Web Security (VII) specific process of authentication with session cookie scheme
shell 脚本中关于用户输入参数的处理
Why should we do feature normalization / standardization?
Smart wax therapy machine based on STM32 and smart cloud
In addition to the prickles that pierce your skin, there are poems and distant places that originally haunt you in plain life
How to design a high concurrency system
【光学】基于matlab涡旋光产生【含Matlab源码 1927期】
2022.2.14 Li Kou - daily question - single element in an ordered array
Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement
Web3 credential network project galaxy is better than nym?
What does a really excellent CTO look like in my eyes
2020 intermediate financial management (escort class)
【学术相关】顶级论文创新点怎么找?中国高校首次获CVPR最佳学生论文奖有感...
Record: install MySQL on ubuntu18.04
Simulation scheduling problem of SystemVerilog (1)
Common PostgreSQL commands
The most valuable thing
Flutter network and data storage framework construction-b1