【发布时间】:2020-01-25 05:06:59
【问题描述】:
我有一个使用 ASP.Net 编写的 api 的 Django 应用程序。我可以从模板(html页面)调用api。有没有办法从views.py调用api?这个我试过了。
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
# Create your views here.
def categorydashboard(request):
r = request.get('xxx.xxx.xx.xxx:xxxx/Category/getSubCategoryNamev2', d=request.GET)
return render (request,'categoryDashboard.html',{})
API 示例数据(这是一个 GET 请求)
[
{
"category_id": 2,
"category_name": "Hyper Mechanical",
"Image_Path": null,
"subcategory": [
{
"category_id": 0,
"category_name": null,
"product_subcategory_id": 37,
"product_subcategory_name": "Lift",
"schema_id": null,
"Image_path": ""
}
]
}
]
服务器运行良好,但是当我调用“categorydashboard”时,查看它的抛出错误 AttributeError: 'WSGIRequest' 对象没有属性 'get' 我是 Django 新手,如果我弄错了,我很抱歉
【问题讨论】: