如何在我想要的 html 页面中显示 Django 模型?

How can I show the Django model in the html page I want?

我无法在不同的页面上显示我创建的模型。它出现在模型管理页面上。

这里models.py

class Bonusrequest(models.Model):

    username = models.CharField(max_length=200,verbose_name="Kullanici Adi")
    name = models.CharField(max_length=200, verbose_name="Ad Soyad")
    created = models.DateTimeField(verbose_name="Tarih")

和views.py

from django.shortcuts import render, redirect
from django.http import HttpResponse,HttpResponseRedirect
from django.template import loader
from django.utils import timezone
import requests
from datetime import datetime
from datetime import timedelta
import json
import time
import pytz
from pytz import timezone
from .models import Bonusrequest
from .apps import Discount
from django.contrib import messages
from django.contrib import auth
from django.contrib.auth import logout
from django.contrib.auth.models import User
from django.contrib.auth.decorators import user_passes_test
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt

from .models import Bonusrequest
    @login_required
    def finance(request):
    
        myModel = Bonusrequest.objects.all()
        return render (request,'pages/finance.html',{"Bonusrequest":myModel})

这里html页

{% extends 'layoutdash.html'%}
{% load static %}


{% block content %}



  <section class="home-section">
    <h1 class="c-grey-900 mT-10 mB-30">Test</h1>
    <hr>
    <table>
      <tr>
        <th>Name</th>
        <th>Username</th>
        <th>Country</th>
      </tr>
      {% for result in Bonusrequest %}
        <tr>
          <td>{{result.name}}</td>
          <td>{{result.username}}</td>
          <td>{{result.created}}</td>
        </tr>
      {% endfor %}
    </table>
    <style>
      table {
        font-family: arial, sans-serif;
        border-collapse: collapse;
        width: 100%;
      }
      
      td, th {
        border: 1px solid #dddddd;
        text-align: left;
        padding: 8px;
      }
      
      tr:nth-child(even) {
        background-color: #dddddd;
      }
      </style>
  </section>
  




{% endblock %}

我这里想做的是把保存在模型中的值显示在这个页面上。你觉得我错过了什么?这里是项目 details.The 这里的问题是在需要的页面上不能这样显示。在我研究过的资料中,用这种方式写一段代码就可以将模型显示在想要的页面上。

该模型table可以在普通管理模板中显示。

我想你可能继承错误或者错误的块内容 所以从模板中删除除以下内容以外的所有内容,以确保是否显示结果

<section class="home-section">
        <h1 class="c-grey-900 mT-10 mB-30">Test</h1>
        <hr>
        <table>
          <tr>
            <th>Name</th>
            <th>Username</th>
            <th>Country</th>
          </tr>
          {% for result in Bonusrequest %}
            <tr>
              <td>{{result.name}}</td>
              <td>{{result.username}}</td>
              <td>{{result.created}}</td>
            </tr>
          {% endfor %}
        </table>
        <style>
          table {
            font-family: arial, sans-serif;
            border-collapse: collapse;
            width: 100%;
          }
          
          td, th {
            border: 1px solid #dddddd;
            text-align: left;
            padding: 8px;
          }
          
          tr:nth-child(even) {
            background-color: #dddddd;
          }
          </style>
      </section>