【发布时间】:2015-01-05 19:25:48
【问题描述】:
我正在尝试使用 curl 命令访问链接 curl -d "user=1&token=3wk-e7621e890e5b8db28948" http://task.woo.gy/api4/index.json 它工作正常 输出是
{"test1": 49, "test2": "awesome", "success": true}
但我不知道如何在 $.ajax 中使用这个 api
当我直接访问此链接时 http://task.woo.gy/api4/index.json
它给了我消息“必须在请求中包含 'user' 和 'token' 参数。”
创建索引的代码
from tokenapi.decorators import token_required
from tokenapi.http import JsonResponse, JsonError
@token_required
def index(request):
if request.method == 'POST':
data = {
'test1': 49,
'test2': 'awesome',
}
return JsonResponse(data)
else:
return JsonError("Only POST is allowed")
【问题讨论】:
标签: jquery python ajax django django-views