Search⌘ K

Solution: Create My Listings Page

Explore how to develop a My Listings page in Django by setting up the URL, creating the view by adapting an existing one, and building a template to display listings. This lesson guides you step-by-step to link listings to detail pages and add buttons for editing and deleting, preparing for user account integration.

My Listings URL

To set up the URL for the My Listings page, add the following piece of code in the urls.py in the app’s directory.

Python
path('my_listings/', views.my_listings, name='my_listings')

My Listings view

Python
def my_listings(request):
my_listings = Listings.objects.order_by('-list_date')
context = {'my_listings': my_listings}
return render(request, 'listings/my_listings.html', context)

The entire my_listings view is just a copy of the all_listings view. This is the case because we haven’t created users yet, so at this point, all listings belong to one person. Once we have different users creating ...