Create a model

class Contact(models.Model):
      name = models.CharField(max_length=100)
      email = models.EmailField(max_length=100)
      subject = models.CharField(max_length=100)
      message = models.TextField()
      mobile = models.IntegerField()
      created_date = models.DateField(auto_now_add=True)

Load View from views.py

from .models import Contact
def indexPageView(request):
        contact = Contact.objects.all()
        return render(request, "index.html",{'contact': contact})

Print data in a template

{% for contact in contact %}
        <h1>{{contact.name}}</h1>
 {% endfor %}
Leave a Comment