模板包含和django视图/ urls。他们如何(做/应该)工作? [英] Template includes and django views/urls. How (do/should) they work?
问题描述
我有一个迷你盒,在悬停时弹出以显示个人资料信息(不断被隐藏)。它的工作原理包括:
I have a mini box that pops up when hovered to reveal profile information(constantly being hidden). It's working due to a template include:
{% for i in leftbar_network|slice:":12" %}
{% include "includes/mini_profile.html" %}
{% endfor %}
但是我想添加一些条件并拉其他信息...例如:检查它们是否可以被消息。拉那个具体的个人资料的朋友计数.. yadda yadda。我有一个URL和视图应该工作。但似乎完全被忽视了。
But I want to add some conditions and pull other information... for instance: check if they can be messaged. pull that specific profiles friend count.. yadda yadda. I have a url and view that should work. But it seems as though they're being completely ignored.
模板:
<div class="mini-profile">
<div class="mini-profile-top">
<a href="/profile/{{i.get_type|lower}}/{{ i.user.username }}/" data-title="{{ i.user.get_full_name }}" data-content="{{i.get_type}}">
<img class="img-frame" width="90" height="90" src="{% if i.avatar %}{% thumbnail i.avatar 120x120 crop %}{% else %}{{ DEFAULT_AVATAR }}{% endif %}" alt="{{ i.user.get_full_name }}" />
</a>
<a href="/profile/{{i.get_type|lower}}/{{ i.user.username }}/" data-title="{{ i.user.get_full_name }}" data-content="{{i.get_type}}">{{ i.user.get_full_name }}</a>
<div>{{ i.get_type }}</div>
</div>
<div class="mini-profile-bottom">
{% if can_message %}
<form method="GET" action="/messages/compose/{{ i.get_type|lower }}/{{ i.user.username }}/">
<button class="btn btn-margin" type="submit">
<i class="icon-envelope"></i> Message
</button>
</form>
{% else %}
<button class="btn btn-margin tooltip-bottom disabled" title="You need to be connected to message {{profile.user.get_full_name}}" type="submit">
<i class="icon-envelope"></i> Message
</button>
{% endif %}
</div>
</div>
有没有办法使用{%include%}并生成一个视图?还是我这样做错了?如果是这样,我应该如何生成一个带有视图和url的迷你盒子可以顺利地弹出?
Is there any way to work with the {% include %} and generate a view around that? Or have I gone about this the wrong way? If so, how should I generate a mini box with a view and url that pops up smoothly?
示例:当将鼠标悬停在用户上时,Google聊天。
Example: Google chat, when hovering over a user.
提前通知您的建议。
推荐答案
我想添加一些条件并拉其他信息...
实例:检查它们是否可以被消息。拉那个特定的配置文件
朋友计数
I want to add some conditions and pull other information... for instance: check if they can be messaged. pull that specific profiles friend count
听起来像你正在寻找一个模板标签,一个包含标签,将被更具体。
Sounds like your are looking for a template tag, for an inclusion tag, to be more specific.
所以你可以把(python / view)逻辑放在你的标签中,并渲染与你的包含类似的适当的html。
So you can put the (python/view) logic in your tag and render the appropiate html similiar to your include.
这篇关于模板包含和django视图/ urls。他们如何(做/应该)工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!