3

i try to setup a ubuntu server with web service that create by django/python , anyone have an resource/tutorial/example code

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

1

See the chapter on non-html content in the Django book.

1 Comment

A link to an external site is not an answer, and should not be posted as such. This should be a comment to the original post, as you've provided no information to make it an actual answer that will be useful in a search in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.