如何启用CKAN数据集的API按钮? [英] How to enable API button for CKAN data set?

查看:218
本文介绍了如何启用CKAN数据集的API按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功为CKAN网站添加了一个数据集。它也可以预览数据集。

I have successfully added a data set for the CKAN site. It enables to preview the data set as well.

以下是数据集的URL

Below is the URL for the data set

testckan.com:5000/dataset/my-data1/resource/4c2647ca-a4ab-4d20-8119-5c3da9d4ae14

By将 api / rest / 添加到URL中,可以将数据集暴露为JSON服务。

By adding api/rest/ to the URL as below enables to expose data sets as a JSON service.

testckan.com:5000/api/rest/dataset/my-data1/resource/4c2647ca-a4ab-4d20-8119-5c3da9d4ae14

我想要做的是添加一个按钮,以便用户可以将数据集视为JSON,而不是在不方便用户的URL中键入数据。

All I want to do is add an button so that user can view the data set as a JSON rather than typing it in the URL which is not user friendly.

我在

http://data.gov.uk/dataset/bona-vacantia-estates-advertisements

根据API&应用。请参阅下面的图片。

under API & APPS. Please see the image below.

如何启用如上所述的CKAN数据集的API按钮?

推荐答案

您将不得不修改包的前端模板(aka dataset)视图。您可以将此更改添加到您自己的CKAN源代码副本中,或者像所提到的Hendrik和data.gov.uk一样,创建一个 CKAN扩展名来修改模板。

You will have to modify the front-end templating for the package (aka dataset) view. You can either add this change to your own copy of CKAN source code, or like Hendrik mentioned and data.gov.uk people have done, create a CKAN extension to modify the templates.

您的功能示例是为data.gov实现的.uk网站是开源的,可在 GitHub 中使用。具体部分位于 read_common .html

Your example of the feature is implemented for the data.gov.uk site which is open source and available in GitHub. The specific part is in the read_common.html:

<b>API: </b><a href="${h.url_for(controller='api', register='package', action='show', id=c.pkg.name, ver='2')}">
${h.url_for(controller='api', register='package', action='show', id=c.pkg.name, ver='2')}
</a>

url_for函数来自ckan.lib.helpers模块,该模块可用于模板 h根据CKAN文档,所以你应该可以直接在模板中使用它,如上面的代码。

The url_for function is from the ckan.lib.helpers module which "is available for templates as 'h'" according to the CKAN docs, so you should be able to use it directly in the template as in the code above.

这篇关于如何启用CKAN数据集的API按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆