当前位置:网站首页>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)
边栏推荐
- Recommend a simple browser tab
- Sustainable service business models
- FBI warning: some people use AI to disguise themselves as others for remote interview
- Su embedded training - Day10
- Ego planner code parsing Bspline_ Optimizer section (2)
- leetcode:11. 盛最多水的容器【双指针 + 贪心 + 去除最短板】
- The most valuable thing
- Webrtc[41] - Analysis of the establishment process of webrtc transmission channel
- [proteus simulation] a simple encrypted electronic password lock designed with 24C04 and 1602LCD
- 为什么要做特征的归一化/标准化?
猜你喜欢

22.2.14 -- station B login with code -for circular list form - 'no attribute' - 'needs to be in path selenium screenshot deviation -crop clipping error -bytesio(), etc

Thesis study - 7 Very Deep Convolutional Networks for Large-Scale Image Recognition (3/3)
![[academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time](/img/06/5a37e2dca9711f8322b657581c3d75.png)
[academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time
知其然,而知其所以然,JS 对象创建与继承【汇总梳理】

Think of new ways

Counting from the East and counting from the West will stimulate 100 billion industries. Only storage manufacturers who dare to bite the "hard bone" will have more opportunities
![[mathematical modeling] ship three degree of freedom MMG model based on MATLAB [including Matlab source code 1925]](/img/a9/d89ee2b88517eea6b3c38d72cf099f.jpg)
[mathematical modeling] ship three degree of freedom MMG model based on MATLAB [including Matlab source code 1925]
![[wallpaper] (commercially available) 70 wallpaper HD free](/img/21/6802da1056a18157b15de85df60cf5.jpg)
[wallpaper] (commercially available) 70 wallpaper HD free

记录在模拟器中运行flutter时报的错

235. 二叉搜索树的最近公共祖先【lca模板 + 找路径相同】
随机推荐
User identity used by startup script and login script in group policy
EGO Planner代码解析bspline_optimizer部分(2)
HOW TO WRITE A DAILY LAB NOTE?
I didn't cancel
my. INI file not found
Suffix derivation based on query object fields
FBI warning: some people use AI to disguise themselves as others for remote interview
Briefly describe the quantitative analysis system of services
SSM整合-前后台协议联调(列表功能、添加功能、添加功能状态处理、修改功能、删除功能)
Counting from the East and counting from the West will stimulate 100 billion industries. Only storage manufacturers who dare to bite the "hard bone" will have more opportunities
Introduction to SSH Remote execution command
为什么要做特征的归一化/标准化?
A green plug-in that allows you to stay focused, live and work hard
Find the median of two positive arrays
The installation path cannot be selected when installing MySQL 8.0.23
Summary of composition materials for 2020 high-frequency examination center of educational resources
Record: pymysql is used in pycharm to connect to the database
Ego planner code parsing Bspline_ Optimizer section (3)
Su embedded training - Day10
“google is not defined” when using Google Maps V3 in Firefox remotely