2009-11-17 41 views

回答

6

還有piston,這是一個用於創建RESTful API的Django框架。它有一個輕微的學習曲線,但很適合Django。

如果你想要的東西更輕巧,西蒙·威利森具有非常nice snippet我以前使用的是很好的模型HTTP方法:

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) 

雅各布·卡普蘭,莫斯對Worst Practices in REST一個很好的文章,可以幫助指導你遠離一些常見的陷阱。

1
+2

到外部網站的鏈接不是答案,也不應該這樣發佈。這應該是對原始帖子的評論,因爲您沒有提供任何信息以使其成爲將來在搜索中有用的實際答案。 – 2011-06-23 00:24:53