<p>所以,我正在开发一个小程序,它应该向<code>firestore database</code>发送值,几乎所有的东西都工作正常,但是我从这部分代码中得到了一个错误。我正在试图保存<code>string</code>中的<code>temp</code></p>
<pre><code> if block == "ITEMS":
champs = form.areaItems.data #Get the user input text field from the WTForm (it's a dict for whatever reason)
itemsChamps = ItemsChamps(champs.values()) #Stock the dict value inside itemsChamps
temp = next(iter(itemsChamps.name)) #Get the 1st value from itemsChamps (I only want the 1st value)
data = {
"items": {
champs: {
"string": temp
}
}
}
</code></pre>
<p>以下是错误:</p>
<pre><code>File "C:\[..]\flaskblog\routes.py", line 63, in ajouter
"string": temp
TypeError: unhashable type: 'dict'
</code></pre>
<p>我的代码可能看起来有点“混乱”,我是个新手,很抱歉</p>
<p>编辑1:现在可以了</p>
<p>我现在觉得自己很笨,我被我写的所有代码弄糊涂了,有一些错误:</p>
<pre><code> if block == "ITEMS":
champs = form.itemsFields.data #I was using the wrong form field...
itemsChamps = ItemsChamps(form.areaItems.data.values()) #I'm now getting all the value from the right field
temp = next(iter(itemsChamps.name)) #Didn't touch this, it work
data = {
"items": {
champs: {
"string": temp
}
}
}
</code></pre>
<p>谢谢你给我一点时间</p>