当我打开django应用程序并查看该网站时 检查是可见的,但我的模型没有打印 我想在html文件中显示我存储在customers模型中的数据
from django.db import models
# Create your models here.
class Customer(models.Model):
name = models.CharField(max_length=1000)
Status =models.CharField(max_length=1000,blank=True, null=True)
def __str__(self):
return self.name
from django.shortcuts import render
from django.template.response import TemplateResponse
from Core.models import Customer
def user_profile(request):
data = Customer.objects.all()
return render_to_response(request,"templates/home.html", {"data": data})
{% extends 'base.html' %}
{% block title %}Video Page
{% endblock %}
{% block content %}
{% for customer in data %}
<h1> {{ customer.name}}</h1>
{% endfor %}
<h1>check</h1>
{% endblock %}
答案 0 :(得分:1)
使用render而不是render_to_response
<Grid>
<ListView ScrollViewer.VerticalScrollBarVisibility="Disabled" x:Name="tStack">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Image Source="{Binding Path=Key, Converter={StaticResource StringToImage}
, ConverterParameter=../Images/ControlIcons/{0}.ico}" />
<TextBlock Text="{Binding Key}" FontSize="10px" Width="60px" Margin="2,0,0,0" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</Grid>