Why the jinja code is being read as HTML text instead of getting executed?

I don't know if I'm asking this question in the right way. Please see this screenshot: https://i.stack.imgur.com/Idl0l.png

directory:

weatherApp

  • core
    • urls
    • views
  • templates
    • index.html
  • weatherApp
    • urls

This is the main project urls

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('core.urls'))
] 

These are app urls and views: core.urls

from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index'),
]

views

from django.shortcuts import render
import urllib.request
import json


def index(request):
    if request.method == 'POST':
        city = request.POST['city']
        source = urllib.request.urlopen('https://api.openweathermap.org/data/2.5/weather?q=' + city + 
            '&units=metric&appid=').read()
        data_list = json.loads(source)

        data = {
            "country_code" : str(data_list['sys']['country']),
            "temp" : str(data_list['sys']['country']),
            "temp_min" : str(data_list['main']['temp_min']),
            "temp_max" : str(data_list['main']['temp_max']),
            "pressure" : str(data_list['main']['pressure']),
            "humidity" : str(data_list['main']['humidity']),
            "wind_speed" : str(data_list['wind']['speed']),
            "wind_dir": str(data_list['wind']['dig']),
            "main" : str(data_list['weather'][0]['main']),
            "description" : str(data_list['weather'][0]['description']),
            "icon" : str(data_list['weather'][0]['icon']),
        }
        print(data)
    else:
        data = {}
        print(data)
    
    return render(request, 'index.html', data)
Back to Top