【发布时间】:2016-08-08 06:12:58
【问题描述】:
我使用 Django 框架开发了一个 webapp,并将其托管在 Digital Ocean 上。服务器应该从使用 Ruby rails 框架编写的客户端接收 Json。
Django 应用程序看不到 Json,因此我想使用 django-cors-headers https://github.com/ottoyiu/django-cors-headers,这需要我安装 django-cors-headers,但我已经托管了该应用程序(即服务器)。
我的问题是(对不起,我是新手)
- 是否可以使用 PUTTY 或 Winscp 在 Digital Ocean 的服务器主机上使用
pip install django-cors-headers安装django-cors-headers?如果是,请问我该怎么做? - 我是否为我的问题选择了正确的解决方案?
以下是服务器的代码 (views.py),我使用的是 Django 1.9 和 python 2.7.6
from django.shortcuts import render
from django.http import HttpResponse
from django.http import JsonResponse
import json
def qucserver (request):
if request.method == 'POST':
print request.body
jsdata = json.loads(request.body)
reply = {"data": jsdata}
return JsonResponse ( reply )
else:
message = 'You submitted an empty form.'
reply = {"Error": message}
return JsonResponse (reply)
输出总是
{data: "json = JSON_DATA"}
【问题讨论】:
标签: ruby-on-rails django heroku digital-ocean django-cors-headers