2014-03-29 27 views
-1

我寫在Django的項目。 我正在將具有數量和天數的出租產品添加到我的購物車中。字符串和整數轉換

這裏是我的代碼。那些代碼在「addToCart.py」

pid=request.urlparams[0] #pid is a product id 
cart = request.session.get('cart',{}) #create a cart 
cart2[pid]= [days,quantity]  # days, quantity are sent in using forms 

在「CheckOut.py」下的那些代碼。現在我想計算總數。

product = product.objects.get(id=pid) # get the product 
quantity=int(cart2[(str(pid)][1])  # this does not work. I need some help about how to do int and string coversion 
total=product.Price*quantity*int(cart2[(str(pid)][0]) # this does not neither. 
+0

你是什麼意思由它不工作。獲取任何異常消息? –

+1

'這不起作用.'不是一個有效的問題。那它不起作用呢?你期望發生什麼?究竟發生了什麼?什麼是輸入?你是否收到錯誤?如果是這樣,那是什麼?請提供完整的追溯。 – That1Guy

+0

括號不匹配 – sshashank124

回答

0

我會建議使用type()函數在內部測試它,它可能是您嘗試轉換的內容不能轉換爲字符串的情況。