<p>嗯,可能提供适当的代码(前面是一个示例)</p>
<pre><code>DictModels = {}
NrChild = request.POST.get('NrPop')
for i in range(int(NrChild)):
if i==0:
Text = (request.POST.get('GB')) + "GB"
title = request.POST.get('ChoiceFieldComputer')
Text += " " + SpecRamAdd.objects.get(id=int(title)).Ram + " "
DictModels[Text] = int(request.POST.get('NrStack'))
else:
j = 0
numberTake = str(i+1)
Text = str(request.POST.get('GB' + numberTake)) + "GB"
title = request.POST.get('ChoiceFieldComputer' + numberTake)
Text += " " + SpecRamAdd.objects.get(id=int(title)).Ram
for j in range(len(DictModels)):
if str(list(DictModels)[j]) == Text:
DictModels.values()[j] += int(request.POST.get('NrStack' + str(numberTake)))
else:
DictModels[Text] = int(request.POST.get('NrStack' + str(numberTake)))
Text = str(DictModels)
TextMail = {
'ShowText': Text,
}
return render(request, 'Order.html', TextMail)
</code></pre>
<p>我选择电脑型号和需要多少内存。然后我想显示段落(“<;p>;”),其中包含闸板的名称和件数。有时两个不同的型号有相同的名称Rams,所以我只想增加件数。所以我不想这样:</p>
<pre><code>DDR3 1666 Mhz x3
DDR3 1333 Mhz x2
DDR3 1333 Mhz x1
</code></pre>
<p>我想这样:</p>
<pre><code>DDR3 1666 Mhz x3
DDR3 1333 Mhz x3
</code></pre>
<p>在本段中:str(list(DictModels)[j])是与变量文本相同的文本。那么为什么它不起作用呢?我早些时候用c#编写了代码</p>