How to add/fetch data from the database in Django

Pinterest LinkedIn Tumblr

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

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