【问题标题】:String and integer conversion字符串和整数转换
【发布时间】:2014-03-29 00:50:14
【问题描述】:

我正在用 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. 

【问题讨论】:

  • 你的意思是它不起作用。收到任何异常消息?
  • this does not work. 不是一个有效的问题。不工作怎么办?你期待发生什么?实际发生了什么?输入是什么?您是否收到错误消息?如果是这样,它是什么?请提供完整的追溯。

标签: python django string integer type-conversion


【解决方案1】:

我建议使用 type() 函数在内部对其进行测试,这可能是您尝试转换的内容无法转换为字符串的情况。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-15
    • 1970-01-01
    • 2020-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-21
    相关资源
    最近更新 更多