【问题标题】:unable to fetch data from sqlite database to html page无法从 sqlite 数据库获取数据到 html 页面
【发布时间】:2020-08-14 00:33:18
【问题描述】:

我是 Shoaib 我是一名学生 我在我的项目中遇到问题问题是我无法将数据从数据库获取到 html 页面 我该如何解决错误 我试图通过它不是固定来修复它很多次 dskjkds jksdkdskl jdfskjlkdsfjlkdfsf jdsfjkljdsl;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>
{% 端块%}

【问题讨论】:

标签: python html django django-models django-views


【解决方案1】:
def first(request):

   student = GeeksModel.objects.all()

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

【讨论】:

    猜你喜欢
    • 2019-10-13
    • 2018-05-28
    • 2012-01-06
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多