How to parse and show info in template with requests_cache

Question:

I have several general questions about requests_cache and how is it working and how can i use that

How can i get json from 3rd party and parse that in my template? I have some information from api that i dont need to write in model in db and i want just to parse that but need just to show that in parsed info in template

views.py

def customer_view(request):

    session = requests_cache.CachedSession('project_budget_cache')
    session.get('http://someurl.com/api')

    return render(request, 'customer/customer_home.html', {'context': session})

I can get request with that but i actually dont know how to show my json in template {{ context }} cant help there

Another question:
How can i synch request every 5 min?

Last question:
How can i avoide problems with 3rd party api? Like if api is closed or they have problems and i cant get json how can i use previous request that was working? I mean if they have problems and cant accept requests rn i need to use request that was made 5 mins ago

Asked By: Kirill_N

||

Answers:

You actually can parse it literally in queryset


        backend = requests_cache.RedisCache(),
                                            password=config()
        session = requests_cache.CachedSession('project_budget_cache', backend=backend, stale_if_error=True,
                                               expire_after=360)
        url = config()
        response = session.get()

           return response.json()
Answered By: Zesshi
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.