作为视图
首先,将此行添加到urls.py:
url(r'^socialaggregator/', include('socialaggregator.urls')),
然后,您将以HTML页面的形式访问提要资源列表,其URL如下:
/socialaggregator/feed/sample/
或者您可以使用json版本:
/socialaggregator/feed/sample/?format=json
还有一个视图显示allressources from all feeds:
/socialaggregator/
这些视图中使用的默认模板来自settings.EDSA_PLUGIN_TEMPLATE。
作为模板标记
标记语法如下:
{% ressource_by_feed slug template_name %}
其中:
- slug参数是包含slug提要的字符串;
- template_name是包含要使用的模板路径的字符串,默认为settings.EDSA_TAG_TEMPLATE;
例如,加载templateTag并使用给它一个feed slug的标记来列出它的资源:
{% load socialaggregator_tags %}
<div class="row">
{% ressource_by_feed 'parrot-apps-usa' %}
</div>
作为django cms插件
只需在页面中使用名为“SocialAggregator提要插件”的插件,选择要列出资源的提要。
默认使用的模板路径来自settings.EDSA_PLUGIN_TEMPLATE若要显示提要资源,请在项目中将其更改为使用自己的HTML布局。
统一内容数据
因为由于饲料可能包含许多社交网络中的子项,所以在模型上存在一个方法。该方法使用从设置RESSOURCE_FORMATTER加载的格式化程序(如果已定义),否则将加载默认格式化程序socialaggregator.formatter.RessourceFormatterDefault。
默认格式化程序返回具有统一数据方案的dict,因此您可以在模板中使用它,而不必测试字段是否已填充,等等。这是可选的,您仍然可以直接使用ressource实例并使用其字段。您可以这样使用:
{% for ressource_item in feed_ressources %}{% with ressource_item.get_unified_render as ressource %}
<li>
{% if ressource.title %}<h2>{{ ressource.title }}</h2>{% endif %}
{% if ressource.description %}<p>{{ ressource.description|safe|linebreaksbr }}</p>{% endif %}
</li>
{% endwith %}{% endfor %}
注意,格式化程序不是自动应用的,因此json视图输出仍然返回序列化的ressource实例。