News for hackers. Stuff that matters.
Re:Backbone.js and Django by izak30 on Tuesday July 05, 2011 @07:26PM (#2731996)
You can directly implement views based on the request method with django's class based views (View) in 1.3. The dispatch method does almost exactly what your restful function does.

Just inherit from View, and define get(), post(), etc.

Re:Backbone.js and Django by rlander on Tuesday July 05, 2011 @09:04PM (#2732185)
Or you could create restful APIs simply with django-piston, django-tastypie or (my new personal favorite) django-dagny.
Re:Backbone.js and Django by izak30 on Tuesday July 05, 2011 @09:32PM (#2732247)
Yes, and there is already a decent wrapper for backbone and tastypie http://joshbohde.com/blog/backbonejs-and-django This is my personal favorite.
Re:Backbone.js and Django by numix on Wednesday July 06, 2011 @12:39AM (#2732588)
Thanks for the recommendation! I'm glad you like it.

As far as wrappers for backbone and tastypie, I think https://github.com/PaulUithol/backbone-tastypie is a pretty good starting point, and a little more complete than what I wrote there.

Re:Backbone.js and Django by izak30 on Wednesday July 06, 2011 @09:36AM (#2733788)
Oh, I thought they were related until now. This one is actually what I _use_. Yours is what came up in a search.
Re:Backbone.js and Django by rlander on Tuesday July 05, 2011 @10:15PM (#2732339)
Nice tutorial, thanks!
Re:Backbone.js and Django by jsdalton on Tuesday July 05, 2011 @10:25PM (#2732358)
I'll throw Django REST Framework in the mix there as well: http://django-rest-framework.org/

Why? See http://django-rest-framework.org/howto/alternativeframeworks...

Re:Backbone.js and Django by joshontheweb on Tuesday July 05, 2011 @08:44PM (#2732142)
I was going to suggest this as well. Each resource can be a class that has a function defined for each method.
Re:Backbone.js and Django by paulsmith on Tuesday July 05, 2011 @07:25PM (#2731994)
Instead of creating a cookie manually, you can save 4 lines and use the .set_cookie()[1] method on the response object.

Also, take a look at the render()[2] shortcut function to collapse the template loading, context settings, and rendering steps into one.

[1]: https://docs.djangoproject.com/en/1.3/ref/request-response/#... [2]: https://docs.djangoproject.com/en/1.3/topics/http/shortcuts/...

Re:Backbone.js and Django by chernevik on Tuesday July 05, 2011 @09:15PM (#2732206)
Further line saving: The << methods >> dictionary isn't needed, it's just mapping lower case strings to upper. Replace:

return methods[request.method](request, item_id)

with:

return request.method.lower(request, item_id)

Re:Backbone.js and Django by theroo on Tuesday July 05, 2011 @07:45PM (#2732030)
Also, setting the cookie 'todos' to todolist.id will allow anyone to manipulate the value of that cookie in order to read anyone's cookies.
Re:Backbone.js and Django by po on Wednesday July 06, 2011 @12:51AM (#2732612)
With Django 1.4 (or the dev version) it will be possible to cryptographically sign a cookie:

https://docs.djangoproject.com/en/dev/topics/signing/

You can use this to store the session data with the user without having to consult a database and without fear that they will tamper with the id:

https://github.com/ericflo/django-cookie-sessions

Re:Backbone.js and Django by dikbrouwer on Wednesday July 06, 2011 @01:26AM (#2732686)
You can replace the toDict() method in your model with the values() method on the default manager. For example: Todo.objects.values('id', 'order', 'content', 'done').get(pk=x)
Re:Backbone.js and Django by drstrangevibes on Wednesday July 06, 2011 @04:51AM (#2733053)
his working demo takes you to his router, with the password prefilled. FAIL
Re:Backbone.js and Django by ccarpenterg on Wednesday July 06, 2011 @09:56AM (#2733890)
It's a dynamic IP so you were pointing to another machine.