python - 无法从 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 © Your Website 2020</div>
<div>
<a href="#">Privacy Policy</a>
·
<a href="#">Terms & Conditions</a>
</div>
</div>
</div>
</footer>
{% 端块%}
解决方案
def first(request):
student = GeeksModel.objects.all()
return render(request, 'student/1.html', {'student' : student})
推荐阅读
- go - 值接收者与指针接收者混淆
- python - 如何使用 lambda 函数根据其他列分配值,同时对多个值使用“或”以获得相同的结果?
- git - 如何让 GitHub 历史记录显示我从其他人那里克隆的代码的历史记录
- css - 在 CSS 4.0 中替代 ms-flex-preferred-size
- elasticsearch - 如何从现有索引在 ElasticSearch 中创建重复索引?
- python - 如何让 conda list 命令仅打印名称列?
- python - 我如何检查邮件内容是否被引用打印编码?
- reactjs - 使用渲染选项自动完成材料未找到酶中的查找元素具有类名
- html - Bootstrap4 图像未显示在屏幕上
- pandas - 如何在数据框的表格中换行(转换为 .png)