Python中文
首页
教程
问答
标签
搜索
登录
注册
Django TypeError:键必须是str、int、float、bool或None,而不是News Chann
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>这是我的登录视图。在</p> <pre><code>def login(request): username = request.data.get("username") password = request.data.get("password") if username is None or password is None: return Response({'error': 'Please provide both username and password'}, status=HTTP_400_BAD_REQUEST) user = authenticate(username=username, password=password) if not user: return Response({'error': 'Invalid Credentials'}, status=HTTP_404_NOT_FOUND) token, _ = Token.objects.get_or_create(user=user) voting_result = Count.objects.filter(userId=user.id) print(voting_result) channel = {} for e in voting_result: channel[e.channelId] = e.rate return Response({'token': token.key, 'user': user.username, 'email': user.email, 'id': user.id, 'stats': channel}, status=HTTP_200_OK) </code></pre> <p>我想在我的回复中添加一个dictionary<strong>频道</strong>。但是我得到了这个错误。在</p> ^{pr2}$ <p>我该怎么做才能让<strong>频道</strong>词典也出现在我的回答中?我将在我的react应用程序中使用它。在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>看起来您需要<code>channelId</code>id作为密钥</p> <p>尝试:</p> <pre><code>for e in voting_result: channel[e.channelId.id] = e.rate </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在python中从数据帧列中删除分类值?
10 回答
如何在python中从数据帧列表中删除引号
10 回答
如何在python中从数据帧创建列表
9 回答
如何在Python中从数据帧创建嵌套的JSON
7 回答
如何在Python中从数据帧显示wordcloud
5 回答
如何在Python中从数据帧的时间戳中删除字符
1 回答
如何在Python中从数据帧绘制简单绘图?
1 回答
如何在python中从数据帧行提取具有特定长度的范围?
2 回答
如何在python中从数据帧设置dict中的值
7 回答
如何在Python中从数据库中获得一个结果
2 回答
如何在python中从数据框中绘制分类条形图
3 回答
如何在Python中从数据框中选择特定细节?
2 回答
如何在python中从数据集中删除unicode
10 回答
如何在python中从数据集中删除某些数值?
2 回答
如何在python中从数据集中选择行
6 回答
如何在Python中从数组中删除元素
7 回答
如何在python中从数组中删除单个倒逗号?
1 回答
如何在python中从数组中删除对象?
7 回答
如何在python中从数组中删除引号
1 回答
如何在python中从数组中删除所有最小值
9 回答