python - 在 django python 中渲染响应
问题描述
使用 django 框架和 rest api 框架。
os.environ['NO_PROXY'] = '#mylocalhosthere'
def api_view(request):
#url = '#mylocalhosthere/pcp/customer/'
url = '#mylocalhostherepcp/customer/?format=json'
r = requests.get(url)
data = json.loads(r.text)
return render(request,'PcPeripherals/api.html',{'response':data})
这就是我的 django 模板的样子:
{% block content %}
<div class="row">
<div class="column-d-9 column-t-12 column-m-12">
<div id="box_contact">
<div id="box_formas">
<h1>List of customers</h1>
{% for i in data%}
<strong>{{i.id}}</strong>
{% endfor %}
</div>
</div>
</div>
</div>
{% endblock content %}
任何想法我做错了什么?
我检查了其他一些变体,我的模板中仍然没有数据。
解决方案
您应该使用“响应”而不是“数据”。
推荐阅读
- sqlite - 使用 Sqlite 在 Ionic3 中看不到我的结果,即使它识别行数
- python - 从电子邮件中提取和统计域地址邮件
- vba - MS Access vba密码保护word文档
- ruby-on-rails - rails 似乎使用“button_to”助手和“get”方法删除 URL 中的查询参数
- vue.js - vue.js如何在鼠标悬停时切换html标签显示
- c# - ASP.NET Web 控件下拉列表对象填充
- javascript - 使用 Google 登录时是否可以刷新页面 - 登录时?
- python - python函数的使用
- php - Laravel index.php 路由问题
- c# - WebSecurity 将 CurrentUserId 显示为 -1