Retrieve specific page content in another app's view

14 views
Skip to first unread message

asdfg

unread,
Apr 27, 2011, 7:35:43 AM4/27/11
to django-...@googlegroups.com
I know there is a documented way of integrating page-cms with external apps. However, I wondered if there was a simpler method for what I want to do. Essentially, I just need to output a single field from a specific page in one of the views in an external app. I've got this in the view:

from pages.models import Content
def example(request):
    pagecontent = Content.objects.filter(page=11, type='content')
    ....

Using {{ pagecontent }} in the template outputs:

[<Content: faculties :: My content here>]

How can I get it to output just the content itself (the 'My content here' bit)?

Nicolas Caniart

unread,
Apr 27, 2011, 7:44:22 AM4/27/11
to django-...@googlegroups.com
A Content object has several attributes, I guess what you wish for is
the 'body' attribute of that object, i.e. :

{{pagecontent.body}}

Should do the trick.

Nicolas

> --
> You received this message because you are subscribed to the Google
> Groups "django-page-cms" group.
> To post to this group, send email to django-...@googlegroups.com.
> To unsubscribe from this group, send email to django-page-cms
> +unsub...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-page-cms?hl=en.

asdfg

unread,
Apr 27, 2011, 7:46:04 AM4/27/11
to django-...@googlegroups.com, nicolas...@cemsi.eu
I already tried that! It doesn't output anything at all then...

captainmish

unread,
Apr 27, 2011, 8:26:40 AM4/27/11
to django-page-cms


On Apr 27, 12:46 pm, asdfg <m...@rkh.co.uk> wrote:
> I already tried that! It doesn't output anything at all then...

You seem to be getting a list back, rather than the actual content,
you could try:

pagecontent = Content.objects.filter(page=11, type='content')[0]

to get the first hit and return a content object rather than a list,
or use get instead of filter?

asdfg

unread,
Apr 27, 2011, 8:30:29 AM4/27/11
to django-...@googlegroups.com
That returns:

faculties :: My content here

('faculties' is the slug of the page btw)

captainmish

unread,
Apr 27, 2011, 8:32:44 AM4/27/11
to django-page-cms
Good, so now you should be able to use in your template:

{{ content.fieldnamethatyouwant }}

asdfg

unread,
Apr 27, 2011, 8:33:59 AM4/27/11
to django-...@googlegroups.com
Ah cool - that's it. Thanks :)

captainmish

unread,
Apr 27, 2011, 8:33:59 AM4/27/11
to django-page-cms
or {{ pagecontent.xyz }} even :)

asdfg

unread,
Apr 27, 2011, 8:39:54 AM4/27/11
to django-...@googlegroups.com
I guessed thats what you meant :)
Reply all
Reply to author
Forward
0 new messages