django select 完成单行并打印
django select complete single row and print
我想 select 完全打印一行。
我的意思是得到name
,address
,city
,state_province
,country
,website
.
以及如何 select onw 行的某些列?
views.py:
from books.models import Publisher
def send(request):
p = Publisher.objects.filter(id='29')
return render(request, 'style.html', {'items': p})
style.html:
{{ items }}
models.py:
from django.db import models
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()
def __str__(self):
return self.name
这就是您访问模板中一行的所有字段的方式。
您在查询集对象上使用点表示法来访问模板中的每个字段(在您的情况下,style.html):
{{ items.name }}
{{ items.address }}
{{ items.city }}
{{ items.state_province }}
{{ items.country }}
{{ items.website}}
我想 select 完全打印一行。
我的意思是得到name
,address
,city
,state_province
,country
,website
.
以及如何 select onw 行的某些列?
views.py:
from books.models import Publisher
def send(request):
p = Publisher.objects.filter(id='29')
return render(request, 'style.html', {'items': p})
style.html:
{{ items }}
models.py:
from django.db import models
class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60)
state_province = models.CharField(max_length=30)
country = models.CharField(max_length=50)
website = models.URLField()
def __str__(self):
return self.name
这就是您访问模板中一行的所有字段的方式。 您在查询集对象上使用点表示法来访问模板中的每个字段(在您的情况下,style.html):
{{ items.name }}
{{ items.address }}
{{ items.city }}
{{ items.state_province }}
{{ items.country }}
{{ items.website}}