2014-03-29 25 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()函数在内部测试它,它可能是您尝试转换的内容不能转换为字符串的情况。