Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误-Django-list_Python_Django_Meta - Fatal编程技术网

Python 属性错误-Django-list

Python 属性错误-Django-list,python,django,meta,Python,Django,Meta,我从Django中的一个简单示例开始,只是测试一些东西,但我得到了一个错误 这是我在my view.py中的代码: def index(request): file = open("wappApp/talk.txt", encoding="UTF-8") data = file.read() file.close() dates = search_date(data) return render(dates, 'wappApp/index.html')

我从Django中的一个简单示例开始,只是测试一些东西,但我得到了一个错误

这是我在my view.py中的代码:

def index(request):
    file = open("wappApp/talk.txt", encoding="UTF-8")
    data = file.read()
    file.close()

    dates = search_date(data)

    return render(dates, 'wappApp/index.html')
日期是日期的列表

在我的模板中,我正在这样做:

<ul>
    {% for days in dates %}
        <li><a>{{ days }}</a></li>
    {% endfor %}
</ul>
{'dates': dates}
    {日期%中的天数为%}
  • {{days}
  • {%endfor%}
但在django,有一件事我并不觉得陌生

这就是错误: “list”对象没有属性“META”

如您所见,任何帮助都将非常有用,render将收到param
请求作为第一个参数,您将给出一个“列表”。试试这个:

return render(request, 'wappApp/index.html', dates)
return render(request, 'wappApp/index.html', context={'dates': dates})
请记住,
dates
是上下文,它应该是
dict
而不是
列表
。如果您将其作为列表,请尝试以下操作:

return render(request, 'wappApp/index.html', dates)
return render(request, 'wappApp/index.html', context={'dates': dates})
更新:

通过您前面提到的错误,我可以看到
日期
是一个列表,因此通过这样做:

<ul>
    {% for days in dates %}
        <li><a>{{ days }}</a></li>
    {% endfor %}
</ul>
{'dates': dates}
我创建了一个dict,其值为
日期
。因此,在模板中,您可以执行以下操作:

{{ dates }}

然后打印整个列表以使用它。

完美先生。谢谢你的帮助。你能在这方面做更多的开发吗:context={'dates':dates}?请我在等着把它标记为正确的