我打算创建自己的友谊视图和所有内容(但我无法弄清楚如何让所有东西都在数据库中工作)所以我选择使用一种名为django-friendship的东西,它似乎相当不错,而且它还带有标签在HTML模板中使用,但现在我试图列出所有的朋友请求,我似乎无法在标签中为语句执行以下操作:
{% friend_requests request.user %}
我希望能做的是
{for friend_requests in request.user}
#show this then that#
该项目的github页面的链接是这样的:https://github.com/revsys/django-friendship
如果涉及到它,我宁愿创建自己的友谊实现,但我不知道从哪里开始。
friend_requests
标记使用模板,该模板已遍历并为您创建列表:
@register.inclusion_tag('friendship/templatetags/friend_requests.html')
def friend_requests(user):
"""
Inclusion tag to display friend requests
"""
return {'friend_requests': Friend.objects.requests(user)}
这是模板
<ul>
{% for friend_request in friend_requests %}
<li>{{ friend_request }}</li>
{% endfor %}
</ul>
要自定义它,请在另一个名为friendship
的目录中创建一个目录templatetags
,然后在应用程序的模板目录中创建一个名为friend_requests.html
的文件,然后您可以在那里自定义输出。