我有两个观点,'orderlist'和'orderview'。 'orderlist'将列出所有订单给用户,而'orderview'将显示一个订单的详细信息。 现在我想组织这样的网址:
/order map to orderlist and show all orders
/order/{id} map to orderview and show detailed info of one order
有没有实现这个?感谢。
答案 0 :(得分:4)
这只是基本的网址发送。
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}