【发布时间】:2016-04-16 06:59:39
【问题描述】:
我正在尝试将 django id 存储到列表中。但它将两位数存储为单独的两位数。例如,它将 10 存储为 1 和 0。它将值存储为 unicode 字符。谁能帮帮我
def practice_view(request, id=None):
msg = ''
if request.method == 'POST':
questions = request.POST.get('Que');
list = [];
result = [];
total = 0;
for i in questions:
if i.isdigit():
list.append(i)
total = total + 1;
During debugging this is what it displays
Que=u'[6, 7, 8, 9, 10, 11, 12]'
questions=u'[6, 7, 8, 9, 10, 11, 12]'
list=[u'6', u'7', u'8', u'9', u'1', u'0', u'1', u'1', u'1', u'2']
【问题讨论】:
-
1.避免使用列表作为变量名。 2.在追加到列表之前将字符串转换为int。
-
尝试
questions = request.POST.getlist('Que')而不是request.POST.get。这仅适用于您在帖子数据中发送多个名称为Que的值。
标签: python django list unicode