首页 > 解决方案 > 无法从 sqlite 数据库获取数据到 html 页面

问题描述

我是 Shoaib 我是学生 我在我的项目中遇到问题 问题是我无法从数据库中获取数据到 html 页面 我该如何修复错误;kjdsafjksjdkfaksdf ds jsdjjk sdjhsd

这是我的意见.py

from django.shortcuts import render, redirect
from .models import GeeksModel

# Create your views here.

def first(request):

   student = GeeksModel.objects.all()

   return render(request, 'student/1.html', {student : 'student'})

这是我的models.py

from __future__ import unicode_literals
from django.db import models

# Create your models here.

class GeeksModel(models.Model):

   admission = models.IntegerField(unique=True)
   name = models.CharField(max_length=50)
   english = models.IntegerField()
   hindi = models.IntegerField()
   maths = models.IntegerField()
   science = models.IntegerField()

   def __str__(self):
       return self.name

这是我的 HTML 页面

{% extends 'admin/adminbase.html'%}
{% block content %}

<div id="layoutSidenav_content">
   <main>
    <div class="container-fluid">
        <h1 class="mt-4">Tables</h1>
        
        <ol class="breadcrumb mb-4">
            <li class="breadcrumb-item"><a href="/panel">Dashboard</a></li>
            <li class="breadcrumb-item active">Tables</li>
        </ol>
        <div class="card mb-4">
            <div class="card-header">
                <i class="fas fa-table mr-1"></i>
                DataTable 
            </div>
 
            <div class="card-body">
                <div class="table-responsive">
                    
                    <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                        <thead>
                            <tr>
                                <th>Id</th>
                                <th>Name</th>
                                <th>Admission No.</th>
                                <th>Science</th>
                                <th>English</th>
                                <th>Hindi</th>
                                <th>Maths</th>
                                <th>action</th>
                            </tr>
                        </thea>
                        <tbody>

                            <tr>
                                <td>{{ student.id }}</td>
                                <td>{{ student.admission }}</td>
                                <td>{{ student.name }}</td>
                                <td>{{ student.science }}</td>
                                <td>{{ student.english }}</td>s
                                <td>{{ student.hindi }}</td>
                                <td>{{ student.maths }}</td>

                                <td class="td-actions text-right">
                                    <a href="/edit/{{ student.id }}">
                                    <button type="button" rel="tooltip" class="btn btn-success">
                                        <i class="material-icons">edit</i>
                                    </button></a>
                                    <a href="/delete/{{ student.id }}">
                                    <button type="button" rel="tooltip" class="btn btn-danger">
                                        <i class="material-icons">close</i>
                                    </button></a>
                                </td>
                               
                            </tr>


                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <center><a href="/signup" class="btn btn-primary">Add New User</a></center>  
        </center>
    </div>
</main>
<footer class="py-4 bg-light mt-auto">
    <div class="container-fluid">
        <div class="d-flex align-items-center justify-content-between small">
            <div class="text-muted">Copyright &copy; Your Website 2020</div>
            <div>
                <a href="#">Privacy Policy</a>
                &middot;
                <a href="#">Terms &amp; Conditions</a>
            </div>
        </div>
    </div>
</footer>
{% 端块%}

标签: pythonhtmldjangodjango-modelsdjango-views

解决方案


def first(request):

   student = GeeksModel.objects.all()

   return render(request, 'student/1.html', {'student' : student})

推荐阅读