...

/

Listings View and Database Queries

Listings View and Database Queries

Learn how to add the path to the listings page, add code for the listings view, and interpret different database queries.

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 above, open views.py from the app’s folder (listings/ ...