Good afternoon, I have a problem and I can't figure it out how to do it. I am using a third party api for data, I am storing it into metar variable and passing it as argument. However it is not working. Any help will be appreciated. Thanks.
Views.py
from urllib.request import Request, urlopen
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic import TemplateView
from django.template.response import TemplateResponse
# Create your views here.
class DashboardView(TemplateView):
template_name = "index.html"
def index(request, template_name="index.html"):
headers = {
'Authorization': 'my_private_api'
}
args={}
request = Request('https://avwx.rest/api/metar/KJFK', headers=headers)
response_body = urlopen(request).read()
args['metar'] = response_body
return TemplateResponse(request,template_name,args)
index.html
{%block content %}
<div>
<h1>Metary</h1>
<p>{{ metar }}</p>
</div>
{%endblock content%}
urls.py
from django.urls import path
from . import views
from dashboard.views import DashboardView
urlpatterns = [
path('', DashboardView.as_view()),
]