August 2016
Beginner to intermediate
717 pages
15h 24m
English
Before using Django to retrieve data from a database, we were using SQL queries to retrieve an object containing the result. With Django, there are two ways to retrieve records from the database depending on whether we want to get back one or several records.
To retrieve records from a model, we must first import the model into the view as we have done before to save the data in a model.
We can retrieve and display all the records in the Project model as follows:
from TasksManager.models import Project from django.shortcuts import render def page(request): all_projects = Project.objects.all() return render(request, 'en/public/index.html', {'action': "Display all project", 'all_projects': all_projects}) ...Read now
Unlock full access