简体   繁体   中英

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

When I open the django app and view the site check is visible but nothing from my model is printed I want to display the data that I have stored in the customers model in the html file

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

use render instead of render_to_response

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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