How to implement a calm web service using python / django

I am trying to configure an ubuntu server using a web service created by django / python, anyone has a resource / tutorial / example code

+3
source share
2 answers

There is also piston , which is the basis of Django for creating RESTful APIs. It has a slight learning curve, but fits well with Django.

If you want something lighter, Simon Willison has a very nice snippet that I used earlier that models HTTP methods well:

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)

- REST, .

+6
+1

Source: https://habr.com/ru/post/1723109/


All Articles