Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Django with GWT? [closed]

Tags:

json

django

gwt

So I know that I can communicate between those two using JSON, but I also know that I would have to manually recreate all Django objects in JS.

Do you know of any tool or library that could help me do that? Or maybe even a better way of achieving the same goal?

I only found these two: http://palantar.blogspot.com/2006/06/agad-tutorial-ish-sort-of-post.html Django + GWT or Jquery

But then I still would have to manually mirror my objects, which would violate DRY.

like image 389
Mononofu Avatar asked Jul 10 '09 10:07

Mononofu


2 Answers

In my Django/GWT project I do use django-piston to expose Django models via REST API, in JSON format. Look at piston's website for more on how to achieve that http://bitbucket.org/jespern/django-piston/wiki/Home.

Then, on GWT side, you only need to create overlay types for your Django models (DevGuideCodingBasicsOverlay).

I use gwt-dispatch (http://code.google.com/p/gwt-dispatch/) with some REST goodness added to fetch my models from Django backend, but you can use you whatever you want (HttpRequestBuilder), then use GWT JSONParser, and by getting JavaScriptObject and casting, you will get your desired model in GWT. It may seems a little too complicated, but it's not, quite the opposite, it's very comfortable to use.

like image 147
skrat Avatar answered Oct 19 '22 23:10

skrat


You don't necessarily have to manually create all Django objects in JS. The GWT consists of just the UI objects, and communicates with the Django back-end to get the model data to display in the browser, and to send updates back. I've used Django back-ends with both Adobe Flex and GWT front-ends, and in neither case did I have to re-create any Django objects in JS. I did, however, use customised JSON encoders in my back-end. This was done so that I could send only the information needed by the UI, rather than everything in a model instance (some of which might be sensitive information).

like image 39
Vinay Sajip Avatar answered Oct 20 '22 01:10

Vinay Sajip