我正在编写一个ToDo列表应用程序,以帮助自己开始使用Python。该应用程序在GAE上运行,我将待办事项存储在数据存储区中。我想将每个人的物品展示给他们,也要单独展示给他们。问题是该应用程序当前向所有用户显示所有项目,因此我可以看到您写的内容,也可以看到我写的内容。我以为将我的todo.author对象转换为字符串并查看它是否与用户名匹配是一个不错的开始,但是我不知道该怎么做。
这就是我的main.py中的内容
...
user = users.get_current_user()
if user:
nickname = user.nickname()
todos = Todo.all()
template_values = {'nickname':nickname, 'todos':todos}
...
def post(self):
todo = Todo()
todo.author = users.get_current_user()
todo.item = self.request.get("item")
todo.completed = False
todo.put()
self.redirect('/')
在我的index.html中,本来是这样的:
<input type="text" name="item" class="form-prop" placeholder="What needs to be done?" required/>
...
<ul>
{% for todo in todos %}
<input type="checkbox"> {{todo.item}} <hr />
{% endfor %}
</ul>
但我只想向创建它们的用户显示项目。我想尝试
{% for todo in todos %}
{% ifequal todo.author nickname %}
<input type="checkbox"> {{todo.item}} <hr />
{% endifequal %}
{% endfor %}
无济于事。列表变成空白。我以为是因为todo.author不是字符串。我可以将值读取为字符串,还是可以将对象转换为String?
谢谢!
鸿蒙传说
桃花长相依
千巷猫影
相关分类