Django如何进行RESTful电话? [英] How do you get Django to make a RESTful call?

查看:90
本文介绍了Django如何进行RESTful电话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我不是想提供一个RESTful API,我正在尝试调用一个。

Note: I'm not trying to provide a RESTful api, I'm trying to call one.

def index( request, *args, **kwargs ):
    context = {}
    context['some_json'] = make_remote_api_call( "http://exampl.com/objects/" )

    return render_to_response( 'index.html', context, context_instance=RequestContext(request) )

或者这是可笑的,我应该让客户总是这样做吗?基本上,我很好奇如何正确分割我的网站,以便不同的服务器(内部受保护的)可以提供不同的信息子集。

Or is this just ridiculous and I should make the client always do it? Basically, I'm curious as to how to properly divide my website so that different servers (internal protected ones) can provide different subsets of info.

推荐答案

使用请求库。这里有一些讨论 - http://news.ycombinator.com/item?id=2882301 ,我在PyOhio做了一个关于使用Python消费Web API的演讲,您可能会发现有趣或有帮助的

Use the requests library. Here is some discussion on it -- http://news.ycombinator.com/item?id=2882301 and I did a talk on "Consuming Web APIs with Python" at PyOhio that you might find interesting or helpful

  • Video http://blip.tv/pyohio/consuming-web-apis-with-python-5439492
  • Slides http://issackelly.github.com/Consuming-Web-APIs-with-Python-Talk/slides/slides.html#intro
  • Code https://github.com/issackelly/Consuming-Web-APIs-with-Python-Talk

这篇关于Django如何进行RESTful电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆