首页 > 解决方案 > 在 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 %}

任何想法我做错了什么?

我检查了其他一些变体,我的模板中仍然没有数据。

标签: pythondjango

解决方案


您应该使用“响应”而不是“数据”。


推荐阅读