转自: https://blog.csdn.net/qiushanjushi/article/details/45098703
并对上面文章进行补充parent_resource 是用法:
map.resource("message", "messages", controller="categories",
path_prefix="/category/{category_id}",
name_prefix="category_")
# GET /category/7/message/1
# Adds named route "category_message"
1、当提供parent_resource ,path_prefix 未提供时,path_prefix 将会自动生成,生成格式:<parent collection name>/:<parent member name>_id
2、当当提供parent_resource ,name_prefix 未提供时,name_prefix 会自动生成,生成格式: <parent member name>_
例如:
>>> m = Mapper()
>>> m.resource('location', 'locations',
... parent_resource=dict(member_name='region',
... collection_name='regions'))
>>> # path_prefix is "regions/:region_id"
>>> # name prefix is "region_"
>>> url('region_locations', region_id=13)
'/regions/13/locations'
>>> url('region_new_location', region_id=13)
'/regions/13/locations/new'
>>> url('region_location', region_id=13, id=60)
'/regions/13/locations/60'
>>> url('region_edit_location', region_id=13, id=60)
'/regions/13/locations/60/edit'
Overriding generated path_prefix:
>>> m = Mapper()
>>> m.resource('location', 'locations',
... parent_resource=dict(member_name='region',
... collection_name='regions'),
... path_prefix='areas/:area_id')
>>> # name prefix is "region_"
>>> url('region_locations', area_id=51)
'/areas/51/locations'
Overriding generated name_prefix:
>>> m = Mapper()
>>> m.resource('location', 'locations',
... parent_resource=dict(member_name='region',
... collection_name='regions'),
... name_prefix='')
>>> # path_prefix is "regions/:region_id"
>>> url('locations', region_id=51)
'/regions/51/locations'