我只是卡住了。 如何在Django上以html格式打印数据库?我有“jegy.html”,我想要打印吉他桌子,但我说,我被卡住了。
views.py:
from django.shortcuts import render, get_object_or_404, render_to_response
def index(request):
return render(request, 'jegyrendeles/index.html', {})
def reg(request):
return render(request, 'jegyrendeles/reg.html', {})
def jegy(request):
return render(request, 'jegyrendeles/jegy.html', {})
def belep(request):
return render(request, 'jegyrendeles/belep.html', {})
models.py 来自django.db导入模型
class Jegy(models.Model):
j_id = models.IntegerField(primary_key=True, blank=True, null=False)
j_nev = models.TextField(blank=True, null=False)
j_place = models.TextField(blank=True, null=False)
class Meta:
managed = False
db_table = 'jegy'
class Rendeles(models.Model):
r_id = models.IntegerField(primary_key=True, blank=True, null=False)
j_id = models.IntegerField(blank=True, null=False)
sz_id = models.IntegerField(blank=True, null=False)
class Meta:
managed = False
db_table = 'rendeles'
class Szemely(models.Model):
sz_id = models.IntegerField(primary_key=True, blank=True, null=False)
sz_nev = models.TextField(blank=True, null=False)
sz_pw = models.TextField(blank=True, null=False)
class Meta:
managed = False
db_table = 'szemely'
答案 0 :(得分:0)
怎么样:
from .models import Jegy
def jegy(request):
data = Jegy.objects.all()
return render(request, 'jegyrendeles/jegy.html', {'data':data})
和jegyrendeles/jegy.html
:
<table>
{% for item in data %}
<tr>
<td>{{ item.j_nev }}</td><td>{{ item.j_place }}</td>
</tr>
{% endfor %}
</table>