Почему код jinja читается как HTML-текст, а не выполняется?

Я не знаю, правильно ли я задаю этот вопрос. Пожалуйста, посмотрите этот снимок экрана: https://i.stack.imgur.com/Idl0l.png

директория:

weatherApp

  • ядро
    • урлы
    • views
  • шаблоны
    • index.html
  • weatherApp
    • урлы

Это основные урлы проекта

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'))
] 

Это урлы приложений и представлений: core.urls

from django.urls import path
from . import views

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

просмотров

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)
Вернуться на верх