[Tutor] build a really simple "json" api from a db

Picio picioslug at gmail.com
Mon Jul 30 23:37:38 CEST 2007


Hi Kent, ok I've decided to go through Django. Now the clue is to find
some simple guide to
output json from my model and maybe I can benefit also for the url
dispatcher to map in a clean way the request coming from my ajax app.

This is what I'd like to do:

ajax app-> URL -> urls.py -> view.py -> ORM -> db

then

view -> json -> ajax app

The second path is something I really have to figure out!
I hope It's right.
Daniele


2007/7/30, Kent Johnson <kent37 at tds.net>:
> Picio wrote:
> > The beginning idea was to build a json API myself. Since I need only
> > to generate json from a db, maybe Django is too much. I'm a Django
> > beginner. I don't know Turbogears.
> > I've not found anything like: "how to build a json api".
> > Maybe MySqldb+simplejson is the enough?
>
> I guess it depends on how you expect the site to grow. If your needs are
> modest and likely to remain so, maybe a Python CGI that reads data from
> MySQL and publishes it with simplejson is fine. You could do this with
> Django but for something really simple it's probably not worth the trouble.
>
> But if the site is going to grow, Django adds a lot, including an object
> model on top of the database, url dispatching and templated views. If
> that will be useful down the road then it might be worth starting with
> Django.
>
> Kent
>
> > Or
> > Is It more simple to learn how to use Django to create a json api?
> >
> > 2007/7/28, Alan Gauld <alan.gauld at btinternet.com>:
> >> "Picio" <picioslug at gmail.com> wrote
> >>
> >>> Hello, I'd like to know the necessary steps to build a json api for
> >>> two table on my db.
> >> Since you seem to be using Django are you sure that isn't built in?
> >>
> >> I use Turbo Gears and JSON is a standard feature turned on by
> >> an option in a method. Django is quite similar to TG in most respects
> >> so I'll be surprised if it can't do JSON directly.
> >>
> >>> I've seen this snippet on the djangosnippet site.
> >>> http://www.djangosnippets.org/snippets/154/
> >>> Is It the right way.
> >> If its on the Django web site and you are using Django then
> >> probably! :-)
> >>
> >> It certainly looks like a recommendation to me.
> >>
> >> --
> >> Alan Gauld
> >> Author of the Learn to Program web site
> >> http://www.freenetpages.co.uk/hp/alan.gauld
> >>
> >>
> >> _______________________________________________
> >> Tutor maillist  -  Tutor at python.org
> >> http://mail.python.org/mailman/listinfo/tutor
> >>
> >
> >
>
>


-- 
http://picio.gotdns.com ...Il mio blog su NSLU2


More information about the Tutor mailing list