繁体   English   中英

我无法在要显示为html的views.py中使用我的models.py数据

[英]I am not able to use my models.py data in views.py that I want to display in as html

当我打开django应用程序并查看站点检查时可见,但是没有打印我的模型中的任何内容,我想在html文件中显示存储在客户模型中的数据

models.py

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

views.py

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})

home.html的

{% extends 'base.html' %}
{% block title %}Video Page
{% endblock %}

{% block content %}


{% for customer in data %}
    <h1> {{ customer.name}}</h1>
{% endfor %}


    <h1>check</h1>

{% endblock %}

使用render而不是render_to_response

def user_profile(request):
    data = Customer.objects.all() 
    return render(request,"templates/home.html", {"data": data})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM