Stream Field issue with image path using api

46 views
Skip to first unread message

GCiTek Dev

unread,
Nov 25, 2021, 11:35:11 PM11/25/21
to Wagtail support
How can i get image path from stream field api of wagtail

Preston Horn

unread,
Nov 26, 2021, 4:13:27 PM11/26/21
to wag...@googlegroups.com
Can you share your code?

On Thu, Nov 25, 2021 at 10:35 PM GCiTek Dev <gcite...@gmail.com> wrote:
How can i get image path from stream field api of wagtail

--
You received this message because you are subscribed to the Google Groups "Wagtail support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wagtail+u...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/wagtail/c548b047-7c9f-4bfc-839e-e67f423d716an%40googlegroups.com.

GCiTek Dev

unread,
Nov 29, 2021, 12:03:34 AM11/29/21
to Wagtail support
My Code:

class BlogPage(Page):
date = models.DateField("Post date",blank=True,null=True)
body = StreamField([
('heading', blocks.CharBlock(form_classname="full title")),
('paragraph', blocks.RichTextBlock()),
('image', ImageChooserBlock()),
])
tags = ClusterTaggableManager(through=ImmigrationPageTag, blank=True)
search_fields = Page.search_fields + [
index.SearchField('body'),
index.FilterField('date'),
]

api_fields = [
APIField('date'),
APIField('body'),
]
content_panels = Page.content_panels + [
MultiFieldPanel([
FieldPanel('date'),
FieldPanel('tags'),
], heading="Article information"),
StreamFieldPanel('body', classname="full"),
]


and Api output :


{ "meta": { "total_count": 1 }, "items": [ { "id": 3, "meta": { "type": "blogs.BlogPage", "detail_url": "http://localhost/api/v2/pages/3/", "html_url": null, "slug": "first-demo-page", "first_published_at": "2021-11-29T04:49:57.108466Z" }, "title": "First Demo page", "body": [ { "type": "heading", "value": "Heading 1", "id": "c7e5a53c-1fad-43cf-9cad-1de46b6c6d2a" }, { "type": "paragraph", "value": "<p data-block-key=\"pba9n\">Write Here paragraph</p>", "id": "f3888bd0-cfa2-445f-9309-82752515457c" }, { "type": "image", "value": 1, "id": "0e7279ee-c82f-40dd-9a01-f1767144c74a" } ] } ] }


Note: so how can i get the path of image in api output {
"type": "image", "value": 1, "id": "0e7279ee-c82f-40dd-9a01-f1767144c74a" }


WagApi.png
Reply all
Reply to author
Forward
0 new messages