我是学习 Django 的初学者,我有一个网站,其中有一部分允许您列出未完成的 . 到目前为止,我只想显示它,每当我使用带有第二个变量的过滤器 ({"items": todos} 我想在模板中显示它时,它都会返回 HTML 框架。
*当我不在 return 语句中添加此变量时,一切正常。我什至尝试从过滤器打印结果,它工作得很好。
def dashboard(response):
print(response.user.username)
if response.method == 'POST':
form = CreateNewList(response.POST)
if form.is_valid():
n = form.cleaned_data['name']
t = ToDoList(name=n)
t.save()
response.user.todolist.add(t)
else:
form = CreateNewList()
todos = ToDoList.objects.filter(user=response.user)
print(todos)
return render(response, 'classy_main/dashboard.html',{"items": todos},{"form":form})
return render(response, 'classy_main/dashboard.html',{"form":form, "list": t})
这是 html 的外观(它将整个页面从“”返回到底部的脚本标签,但只是为了给你一个想法):
<div class="news links nav-content">News</div>
<div class="more links nav-content">More</div>
<div class="notification">
<a href="#" class="notification">
<span><i class="fa fa-bell" style="font-size: 30px"></i></span>
<span class="badge"></span>
</a>
</div>
<div class="logOut">
是我得到的,而不是真正的页面。