Home > Mobile >  Render response in django python
Render response in django python

Time:09-28

Using django framework and rest api framework.

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})

This is what my django template looks like:

{% 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 %}

Any ideas what I am doing wrong?

I checked some other variants still no data in my template.

CodePudding user response:

You should use 'response' not 'data'.

  • Related