python cms api_buttercms-python-API首个博客和CMS平台为开发者打造-Adam Yala Documentation Jump to: Installation Us...

本文档介绍了如何使用ButterCMS的Python库来访问其API,包括安装、基本用法和各种资源(如文章、页面、作者、类别、标签等)的获取方法。通过简单的示例代码,展示了如何通过API获取和操作内容。
摘要由CSDN通过智能技术生成

作者:Adam Yala

### 作者邮箱:adam@adamyala.com

### 首页:https://github.com/buttercms/buttercms-python

### 文档:None

### 下载链接 https://github.com/buttercms/buttercms-python/tarball/0.1

# buttercms-python

Python Library for ButterCMS API.

Documentation

For a comprehensive list of examples, check out the API documentation.

Jump to:

Installation

Install from PyPi using pip, a package manager for Python.

pip install buttercms-python

Usage

Getting started with the ButterCMS API couldn't be easier. Use your authorization token to create a ButterCMS client.

from butter_cms import ButterCMS

auth_token = "XXXXXXXXXXXXXXXXXXX"

client = ButterCMS(auth_token)

All methods return dictionaries. The data can be navigated using keys and indexes like the example below.

response = client.posts.all()

posts = response['data']

# posts now contains a list of post dictionaries

my_post = posts[0]

# my_post contains the first returned post

print(my_post)

# {

# "url": "http://www.example.com/blog/this-is-a-blog-post",

# "created": "2015-06-12T13:59:32.441289Z",

# "published": "2015-06-12T00:00:00Z",

# ...

# }

Pages

The Page's .all() and .get() methods accept an optional params to add additional data to the response.

client.pages.all('news')

# Optional params

client.pages.all('news', {'foo': 'bar'})

client.pages.get('news', 'hello-world')

# Optional params

client.pages.get('news', 'hello-world', {'foo': 'bar'})

Collections

For a list of params see the API documentation

.get() method accepts an optional params dict to add additional data to the response.

client.content_fields.get(['collection_key'], {'locale': 'en'})

Blog Engine

Posts

client.posts.all({'page_size': 3, 'page': 1, 'exclude_body': 'true'})

client.posts.get('hello-world')

client.posts.search('query', {'page': 1, 'page_size': 10})

Authors

The Author's .all() and .get() methods accept an optional params to add additional data to the response.

{'include':'recent_posts'}: Adds each author's posts under the recent_posts key in that author's returned dictionary

client.authors.all()

client.authors.all({'include':'recent_posts'})

client.authors.get('jennifer-smith')

client.authors.get('jennifer-smith', {'include':'recent_posts'})

Categories

The Category's .all() and .get() methods accept an optional params to add additional data to the response.

{'include':'recent_posts'}: Adds posts tagged with that category under the recent_posts key in that category's returned dictionary

client.categories.all()

client.categories.all({'include':'recent_posts'})

client.categories.get('product-updates')

client.categories.get('product-updates', {'include':'recent_posts'})

Tags

The Tag's .all() and .get() methods accept an optional params to add additional data to the response.

{'include':'recent_posts'}: Adds posts tagged with that tag under the recent_posts key in that tag's returned dictionary

client.tags.all()

client.tags.all({'include':'recent_posts'})

client.tags.get('product-updates')

client.tags.get('product-updates', {'include':'recent_posts'})

Feeds

client.feeds.get('rss')

client.feeds.get('atom')

client.feeds.get('sitemap')

Other

View Python Blog engine and Full CMS for other examples of using ButterCMS with Python.

Tests

To run tests:

python -m unittest butter_cms/unit_tests.py

Copy from pypi.org

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值