Reputation: 1171
I have two views, the 'orderlist' and the 'orderview'. 'orderlist' will list all orders to user, while 'orderview' will show detailed information of one order. Now I'd like to organize the URL like this:
/order map to orderlist and show all orders
/order/{id} map to orderview and show detailed info of one order
Is there anyway to implement this? Thanks.
Upvotes: 0
Views: 223
Reputation: 23331
This is just basic URL dispatch.
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}
Upvotes: 4