from django.http import HttpResponse
import urllib2
Prefix="http://www.abc.com/"
opener = urllib2.build_opener(urllib2.ProxyHandler({'http':Prefix}))
urllib2.install_opener(opener)
def api(request):
url = request.get_full_path()
url = Prefix+url
req = urllib2.Request(url, headers=request.META)
conn = urllib2.urlopen(req)
info = conn.info()
data = conn.read()
return HttpResponse(data, content_type=info.get("content-type"))
在view.py中实现如上,
在url.py中添加对应的路由即可:
url(r'^$', api),