How to print data on dynamic pages?

I made a GET request to my own API, which does not use Frappe in the get_context function. However, I’m not being able to print the result on the html page.

This is my get_context file

import requests

def get_context(context):
    request = requests.get(my-url)
    context.data = request

This is my html file

{{ data }}

Unfortunately, it simply prints {{ data }} on the browser

Can you help me? Thanks in advance!

try debugging, add a print statement and see what is the value of request

Where can I see the result of the print ?

I can see nothing on the bench start console

You should Keys with Data

for example

def get_context(context):
    request = requests.get(my-url)
    text=request.text
    mydata=json.loads(text)
    context.data = mydata

In html page try something like this -----------

{% for i in mydata['data'] %}
                            <li>
                                <div class="dept-row ">
                                    <span><img src="{{i['image']}}" alt=""></span>
                                    <span>{{i['job_title']}}</span>
                                    <span>{{i['number_of_positions']}}</span>
                                </div>
                            </li>
                            {% endfor %}
1 Like