我有两个视图,“订单列表”和“订单视图”。'orderlist' 将列出所有订单给用户,而'orderview' 将显示一个订单的详细信息。现在我想像这样组织 URL:
/order map to orderlist and show all orders
/order/{id} map to orderview and show detailed info of one order
有没有办法实现这个?谢谢。
这只是基本的 URL 调度。
config.add_route('all_orders', '/order')
config.add_route('order_detail', '/order/{id}')
@view_config(route_name='all_orders', renderer='all_orders.mako')
def all_orders_view(request):
all_orders = {} # query the DB?
return {'orders': all_orders}
@view_config(route_name='order_detail', renderer='order_detail.mako')
def order_detail_view(request):
order_id = request.matchdict['id']
order = None # query the db for order
if order is None:
raise HTTPNotFound
return {'order': order}