0
我試圖獲得通過從請求Django獲取的類別ID過濾的項目。它看起來像這樣:來自url的多個請求filtr Djjango
url(r'^productlist.aspx&category(?P<category>\d*)$', 'shop.views.shoplist'),
所以URL看起來像:
http://example.com/store/productlist.aspx&category6
其中 「6」 是類別ID
這裏是views.py
def shoplist(request, category, format=None):
args = {}
args.update(csrf(request))
args['products'] = ShopProduct.objects.all().order_by('-id')
if category:
args['products'] = ShopProduct.objects.filter(shop_product_category_id = category)
return render_to_response('shop-catlist.html', args)
它工作的很好,但niw我想過濾產品的多個類別ID的
的URL會看起來像這樣:http://example.com/store/store.aspx&category1,2,3,4,5
請幫我
注:ID的將通過在形式上覆選框被收集的類別,URL將產生根據用JavaScript
選擇複選框
嗯,是療法以任何方式通過「?」或者用一些東西代替?由於我提供的網址格式是簡化的網址格式,因此它原來的格式如下所示:url(r'^ productlist.aspx&shop(?P \ d *)&category(?P \ d *)&subcategory(?P \ d *)&discount(?P \ d *)$','shop.views.shoplist'),' –
這正是您不應該在URL中做這些的原因,而是作爲查詢參數。 –
'example.com/store/productlist/?category=1&category=2&category=3?subcategory=1&subcategory=4&subcategory=13'可以顯示不同的參數查詢嗎? –