Почему мой HTML-шаблон в Django не отображается в браузере?
У меня проблемы с отображением HTML шаблона, который имеет переменные, переданные ему из моего views.py в проекте Django.
Все вроде бы работает, за исключением того, что при посещении HTML в браузере на моей локальной машине отображается HTML-код, а не созданная страница с содержимым.
файлы находятся ниже.
VIEWS.PY
URLS.PY
from django.contrib import admin
from django.urls import path
import nba.views as views
urlpatterns = [
path('admin/', admin.site.urls),
path('nba/', views.basketball_nba, name='basketball_nba'),
]
NBA.HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>NBA TESTING</title>
</head>
<body>
<!-- TODAY'S EVENTS - WIN ODDS -->
<h3>Today's NBA Games Odds</h3>
<div class="table-responsive" style="width: 1000px;">
<table class="table">
<thead>
<tr>
<th>Bookie</th>
<th>Home</th>
<th>Home Odds</th>
<th>Away</th>
<th>Away odds</th>
</tr>
</thead>
<tbody>
{% for h2h in entain_h2h_today %}
<tr>
<td>Entain</td>
<td>{{ h2h.home_team }}</td>
<td>{{ h2h.home_odds }}</td>
<td>{{ h2h.away_team }}</td>
<td>{{ h2h.away_odds }}</td>
</tr>
{% endfor %}
{% for h2h in unibet_h2h_today %}
<tr>
<td>unibet</td>
<td>{{ h2h.home_team }}</td>
<td>{{ h2h.home_team_h2h_odds }}</td>
<td>{{ h2h.away_team }}</td>
<td>{{ h2h.away_team_h2h_odds }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>
СТРАНИЦА В БРАУЗЕРЕ
https://res.cloudinary.com/puntmedia/image/upload/v1670390244/nbatesting_cmo9b5.png
Похоже, что вы не возвращаете h2h нигде в представлениях.
Посмотрите на эту структуру:
def user_coach_response_view(request):
data=UserFitnessModel.objects.all()
return render(request,'user/user-coach-response.html',{"data":data})
{% for k in data %}
<div class="d-block services-wrap text-center">
<div class="img"><img style="width:320px; height:190px;" src="{% static 'main/images//bg_2.jpg' %}"></div>
<div class="media-body p-2 mt-3">
<h3 class="heading">Name: {{k.user_id.name}}</h3>
<h3 class="heading">Hieght: {{k.hieght}}cm</h3>
<h3 class="heading">Wieght: {{k.wieght}}kg</h3>
<p><a href="/user-coach-response/{{k.user_fitness_id}}" class="btn btn-primary btn-outline-primary">Read more</a></p>
</div>
</div>
{% endfor %}