I'm not an expert, but I just happen to be working on something similar.
I already had the URLs set up so that the HTML was being rendered,
edited, saved, etc. So, then I wanted to add a RESTful API, mirroring
the same URLs. A regular URL looks like:
http://localhost:8000/person/764526236
I decided to make the REST API look like:
http://localhost:8000/person/764526236/?format=json
That was as easy as something like this (person is the view, 764526236
is the handle):
try:
obj = Person.objects.get(handle=handle)
except:
raise Http404(_("Requested %s does not exist.") % view)
if not check_access(request, context, obj, act):
raise Http404(_("Requested %s does not exist.") % view)
if "format" in request.GET:
if request.GET["format"] == "json":
person = db.get_person_from_handle(obj.handle)
content = str(person.to_struct())
response = HttpResponse(content, mimetype="application/json")
return response
The 'if "format"' handles the different formats.
Hope that helps (or someone can point us both in a better direction).
-Doug
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
django-users...@googlegroups.com.
> To post to this group, send email to
django...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/django-users.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/django-users/cc10edc2-e978-461e-986f-43dd73eea63e%40googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.