How do you use Django forms when receiving JSON Ajax requests from iPad?
I am sending many JSON requests from a native iPad app to my Django web server. How do I translate the forms I use on my website to handle the iPad Web Service?
I'm trying to solve the wrong issue, should I recycle a web service used from native iPad apps to use REST-ful requests?
a source to share
Well, first of all, this question really should be:
"How do I write a RESTful API with Django and JSON?"
iPads are like any other web browser (client) and they can use javascript, JSON, etc.
Here is a detailed description of what you need to do:
- Write a Django view and map it to a url like: / api / some_action /
- Write out the body of your view, do any action on the server.
- Write HTML / javascript code that is displayed on the user's iPad so that iPad users visit part of your site (let's say / home /) they will make a JSON request to your server that talks to the API (for example send some JSON to / api / some_action /)
Once your Javascript code sends JSON to the API view, your view should process that JSON and perform whatever actions you want.
This is how most web services evolve.
Hope it helps!
a source to share
Can the iPad (or iPhone / iPod) browser send PUT / DELETE commands? For me this is the biggest problem when trying to make REST-like applications in JavaScript.
At the end of the day, I tend to have small Django views (mostly using generic views create_update
) to handle HTML / form / model integration; and in JS I am using jQuery $('#dialog').dialog().load('dialogurl')
to open a dialog and load it with a form created by Django. Be sure to either drive submit()
yourself.
I'd rather just write a REST server (perhaps using Django-Piston) and a complete client application in the browser; but so far I haven't found a good enough JS framework. (pajamas or qooxdoo sound great but fall "a little shorter")
a source to share
Django TastyPie addresses this need - RESTful and Ajax are suitable for iOS (iPhone / iPad) and Android tablet.
http://django-tastypie.readthedocs.org/en/latest/index.html
http://django-tastypie.readthedocs.org/en/latest/tutorial.html#adding-to-the-api
This makes even more data available, so if we start the server again, the following urls should work:
* http://127.0.0.1:8000/api/v1/?format=json
* http://127.0.0.1:8000/api/v1/user/?format=json
* http://127.0.0.1:8000/api/v1/user/1/?format=json
* http://127.0.0.1:8000/api/v1/user/schema/?format=json
* http://127.0.0.1:8000/api/v1/user/set/1;3/?format=json
* http://127.0.0.1:8000/api/v1/entry/?format=json
* http://127.0.0.1:8000/api/v1/entry/1/?format=json
* http://127.0.0.1:8000/api/v1/entry/schema/?format=json
* http://127.0.0.1:8000/api/v1/entry/set/1;3/?format=json
Here's a demo https://github.com/natea/Valentunes
This has a web client iPhone app (search for it).
a source to share