【问题标题】:ValueError: dictionary update sequence element #0 has length 28; 2 is requiredValueError:字典更新序列元素#0 的长度为 28; 2 是必需的
【发布时间】:2019-08-10 08:09:52
【问题描述】:

我在我的一个 django 视图中收到此错误。这是什么意思?我该如何解决这个问题?下面是我收到错误的视图,

def duedate(request):
    data = Task.objects.all()
    total_count = data.count()
    pending_count = 0
    for dat in data:
        if dat.done == False:
            pending_count += 1
    today = datetime.date.today()
    context = {'data':data, 'today':today, 'count':total_count, 'pending':pending_count}
    return render(request, 'todoapp/index.html', context)

编辑1: 这就是我“ipdb”字典时得到的结果

         36     import ipdb; ipdb.set_trace()
         37     context = {'data':data, 'today':today, 'count':total_count, 'pending':pending_count}
    ---> 38     return render(request, 'todoapp/index.html', context)

    ipdb> context                                                                                                                                         
    {'data': <QuerySet [<Task: Finish todo list>, <Task: create views to display due date>]>, 'today': datetime.date(2019, 3, 19), 'count': 2, 'pending': 2}

【问题讨论】:

标签: python django


【解决方案1】:

问题出在 settings.py 文件中。我在 TEMPLATES 中添加了一个自定义模板标签。我只需要删除它。

【讨论】:

    猜你喜欢
    • 2015-02-22
    • 2021-04-01
    • 2017-12-27
    • 1970-01-01
    • 1970-01-01
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多