Serialize Data for JSON output

38 views
Skip to first unread message

Dave Sayer

unread,
Dec 20, 2010, 10:16:40 AM12/20/10
to django...@googlegroups.com
Hi,

I am working on a photo portfolio site at the moment and for the
gallery side of things, I am using django-photologue to provide much
of the backend muscle. It's working great so far but I really want to
use an image slider/carousel to provide a nice, slick way of
navigating the photos.

I am reckoning the best way to do this is to grab all the photos in a
gallery and slap them into a JSON string, which is then fed through my
slider script. So far, I have got the data into a serialized array
using:

gallery_thumbs_json_s = serializers.serialize('json', gallery_thumbs,
fields=('image', 'title', 'caption', 'tags', 'title_slug',
'date_taken'))

Where I am now stuck, is how to use this as JSON in my script. I have
read that deserialize is the way to do it but I can't get my head
around what comes after deserialize.

Any pointers would be much appreciated.

Cheers,

Dave

--
---------------------------------------
Dave Sayer | Bath Design
Web design & development with standards
---------------------------------------
mobile: +44 (0)7702787436
email: da...@bathdesign.co.uk
web: http://bathdesign.co.uk
twitter: http://twitter.com/sweet_grass
photography: http://luxumbra.co.uk
---------------------------------------

Nick

unread,
Dec 20, 2010, 11:42:17 AM12/20/10
to Django users
This sounds like it is an issue with your JS for your carousel.

If you are needing to get your JSON directly into your JS code then
you can just make gallery_thumbs_json_s list as a variable
{'caro_list': gallery_thumbs_json_s}

and then just call it in your template
> email: d...@bathdesign.co.uk

Dave Sayer

unread,
Dec 20, 2010, 12:49:52 PM12/20/10
to django...@googlegroups.com
Thanks for your response, Nick.

I have called the gallery_thumbs_json variable in my template and get
a very comprehensive array of data, which is nice. I have then set
this as a js var and then passed that to my javascript via eval(),
which gives me a nicely formatted array but i can't work out how to
access specific data in the array. I'll have a hunt around on google.
I think this is now a bit off topic for the Django list.

Thanks for your help.

Dave

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

--
---------------------------------------
Dave Sayer | Bath Design
Web design & development with standards
---------------------------------------
mobile: +44 (0)7702787436

email: da...@bathdesign.co.uk

Reply all
Reply to author
Forward
0 new messages