https://docs.wagtail.io/en/stable/advanced_topics/api/v2/usage.html#fetching-content

 

Wagtail API v2 Usage Guide — Wagtail Documentation 2.15.1 documentation

To fetch content over the API, perform a GET request against one of the following endpoints: Wagtail sites contain many page types, each with their own set of fields. The pages endpoint will only expose the common fields by default (such as title and slug)

docs.wagtail.io

 

API에서 원하는 data를 가져오는 방법 정리

HomePage API

 

 

1) 모든 데이터 가져오기

?fields=*

 

2) 특정 조건에 맞는 page가져오기 (GET메소드랑 동일하다.)

?title=Home or ?id=3 ...

 

3) 모든 데이터 가져오지 말기

?fields=_

 

4) 특정 데이터 가져오지 말기

?fields=-title
?fields=*,-title

 

5) 특정 데이터들 가져오지 말기

?fields=-title,-id

 

6) 특정 데이터만 가져오기

?fields=_,id,title,banner_title ...

 

7) 특정 페이지 갯수만 가져오기 (앞쪽부터 가져오기)

?limit=4
?limit=4&offset=4 -> 앞에 4페이지를 제외한 페이지 가져오기

 

8) 특정 field 기준으로 정렬하기

?order=title
?order=-title -> 역차순
?order=random -> 랜덤으로 가져오기

 

 

9) 메뉴 가져오기

?show_in_menus=true

 

10) 특정 Page의 자식 Pages 가져오기

?child_of=5 -> id가 5인 page의 자식 pages 가져오기
?descendant_of=5

 

11) 검색하기

?search=blog
search_fields = Page.search_fields + [

]

 

12) html_url

http://127.0.0.1:8000/api/v2/pages/?html_path=/ -> HomePage
http://127.0.0.1:8000/api/v2/pages/?html_path=blog/blog-post-1/ -> SPA에 유용

 

+ Recent posts