title: Django - passing variable from function view into html template
body: <p>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 <code>metar</code> variable and passing it as argument. However it is not working. Any help will be appreciated. Thanks.  </p>
  
  <p>Views.py</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>index.html</p>
  
  <pre><code>{%block content %}
  &lt;div&gt;
     &lt;h1&gt;Metary&lt;/h1&gt;
     &lt;p&gt;{{ metar }}&lt;/p&gt;
  &lt;/div&gt;
  {%endblock content%}
  </code></pre>
  
  <p>urls.py</p>
  
  <pre><code>from django.urls import path
  from . import views
  from dashboard.views import DashboardView
  
  urlpatterns = [
      path('', DashboardView.as_view()),
  ]
  </code></pre>