gpt4 book ai didi

python - 如何用python/django实现restful webservice

转载 作者:太空宇宙 更新时间:2023-11-03 13:24:48 24 4
gpt4 key购买 nike

我尝试使用由 django/python 创建的 Web 服务设置一个 ubuntu 服务器,任何人都有资源/教程/示例代码

最佳答案

还有piston ,这是一个用于创建 RESTful API 的 Django 框架。它有一个轻微的学习曲线,但非常适合 Django。

如果你想要更轻量的东西,Simon Willison 有非常 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)

Jacob Kaplan-Moss 在 Worst Practices in REST 上发表了一篇不错的文章这有助于引导您远离一些常见的陷阱。

关于python - 如何用python/django实现restful webservice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1749005/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com