Your context variable for all students is “stud”. Try changing that to “Student” as you refer to it in your template.
- Tom > On May 5, 2019, at 7:09 AM, anchal agarwal <[email protected]> wrote: > > I want to display the name of all the students from the Student model using > cards , i have set it all up but it isn't displaying anything, here are my > files > > models.py > > from django.db import models > from django.utils import timezone > from datetime import date > from ckeditor.fields import RichTextField > > class Student(models.Model): > full_name=models.CharField(max_length=70) > D_O_B=models.TextField() > def _str_(self): > return self.full_name > > class Article(models.Model): > pub_date=models.DateField(default=timezone.now()) > headline=models.CharField(max_length=70) > content=RichTextField() > reporter=models.ForeignKey(Student,on_delete=models.CASCADE) > > > > urls.py > > from django.urls import path > from . import views > > app_name="students" > > urlpatterns=[ > path('Students.html/',views.homepage,name='homepage'), > path("<str:full_name>/",views.detail,name='detail'), ] > > > views.py > > from django.shortcuts import render > from django.http import HttpResponse > from .models import Student > > > def homepage(request): > context={"stud": Student.objects.all} > print(Student.objects.all) > return render(request,"students/Students.html",context) > > def detail(request,full_name): > return HttpResponse("You are looking %s!!" % full_name) > > Students.html > <head> > <!-- Compiled and minified CSS --> > <link rel="stylesheet" > href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css > > <https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css>"> > > <!-- Compiled and minified JavaScript --> > <script > src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js > > <https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js>"></script> > </head> > <body> > <div class="row"> > {% for stud in Student %} > <div class="col s12 m6"> > <div class="card blue-grey darken-1"> > <div class="card-content white-text"> > <span class="card-title">{{stud.full_name}}</span> > <p>{{stud.D_O_B}}</p> > </div> > <div class="card-action"> > <a href="#">This is a link</a> > <a href="#">This is a link</a> > </div> > </div> > </div> > {% endfor %} > </div> > > > </body> > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > Visit this group at https://groups.google.com/group/django-users > <https://groups.google.com/group/django-users>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAMT%3DisXCa7Yc-vM3%2B5c0jWdCX8hgwJFN2tRtCqkK2NbzzqX-nA%40mail.gmail.com > > <https://groups.google.com/d/msgid/django-users/CAMT%3DisXCa7Yc-vM3%2B5c0jWdCX8hgwJFN2tRtCqkK2NbzzqX-nA%40mail.gmail.com?utm_medium=email&utm_source=footer>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ECEE1C89-29E7-45D7-A7F0-DCBE7DB4CE66%40gmail.com. For more options, visit https://groups.google.com/d/optout.

