5 ms·
Backbone.js and Django
- paulsmith 15y agoInstead 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/#django.http.HttpResponse.set_cookie https://docs.djangoproject.com/en/1.3/ref/request-response/#... [2]: https://docs.djangoproject.com/en/1.3/topics/http/shortcuts/#render https://docs.djangoproject.com/en/1.3/topics/http/shortcuts/...
- theroo 15y agoAlso, setting the cookie 'todos' to todolist.id will allow anyone to manipulate the value of that cookie in order to read anyone's cookies.
- po 15y agoWith Django 1.4 (or the dev version) it will be possible to cryptographically sign a cookie: https://docs.djangoproject.com/en/dev/topics/signing/ 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 https://github.com/ericflo/django-cookie-sessions
- chernevik 15y agoFurther 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)
- izak30 15y agoYou 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.
- deleted 15y ago[deleted]
- joshontheweb 15y agoI was going to suggest this as well. Each resource can be a class that has a function defined for each method.
- rlander 15y agoOr you could create restful APIs simply with django-piston, django-tastypie or (my new personal favorite) django-dagny.
- izak30 15y agoYes, and there is already a decent wrapper for backbone and tastypie http://joshbohde.com/blog/backbonejs-and-django http://joshbohde.com/blog/backbonejs-and-django This is my personal favorite.
- rlander 15y agoNice tutorial, thanks!
- numix 15y agoThanks 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 https://github.com/PaulUithol/backbone-tastypie is a pretty good starting point, and a little more complete than what I wrote there.
- izak30 15y agoOh, I thought they were related until now. This one is actually what I _use_. Yours is what came up in a search.
- jsdalton 15y agoI'll throw Django REST Framework in the mix there as well: http://django-rest-framework.org/ http://django-rest-framework.org/ Why? See http://django-rest-framework.org/howto/alternativeframeworks.html#why-use-django-rest-framework http://django-rest-framework.org/howto/alternativeframeworks...
- dikbrouwer 15y agoYou 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)
- drstrangevibes 15y agohis working demo takes you to his router, with the password prefilled. FAIL
- ccarpenterg 15y agoIt's a dynamic IP so you were pointing to another machine.