Search⌘ K
AI Features

Listings View and Database Queries

Explore how to develop a Listings page in a Django web application by setting up URLs, creating views to query the database, and rendering data through templates. Understand basic Django database queries to retrieve and display listings from newest to oldest, and gain practice passing data from models to templates for dynamic content presentation.

Let’s continue building our website by creating a Listings page that will display the listings that we create. To do this, we’ll create a URL, a view, and a template.

Listings URL path

You can see the urls.py opened in the following widget. We added the path to the listings page in line 11. We called it all_listings here, but you can choose your own names.

Note: When you run the app, you will see an empty Listings page with just a heading displaying “LISTINGS”. We will populate the Listings template later.

"""
ASGI config for example project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'example.settings')

application = get_asgi_application()
Listings URL and view

Listings view

In the widget ...