i try to setup a ubuntu server with web service that create by django/python , anyone have an resource/tutorial/example code
+6
A:
There is also piston, which is a Django framework for creating RESTful APIs. It has a slight learning curve, but nicely fits into Django.
If you want something more lightweight, Simon Willison has very nice snippet that I have used previously that nicely models the HTTP methods:
class ArticleView(RestView):
def GET(request, article_id):
return render_to_response("article.html", {
'article': get_object_or_404(Article, pk = article_id),
})
def POST(request, article_id):
# Example logic only; should be using django.forms instead
article = get_object_or_404(Article, pk = article_id)
article.headline = request.POST['new_headline']
article.body = request.POST['new_body']
article.save()
return HttpResponseRedirect(request.path)
Jacob Kaplan-Moss has a nice article on Worst Practices in REST that can help guide you away from some common pitfalls.
John Paulett
2009-11-17 14:01:46