5.8.5 Building a Post List Page

With our blog app connected via URL configuration, we can now add URL patterns. Let’s start with a list of blog posts.

In /blog/views.py, our function view is straightforward, as you can see in Example 5.49.

Example 5.49: Project Code

blog/views.py in 928c982c03

 1  from django.shortcuts import render  2  3  from .models import Post  4  5  6  def post_list(request):  7      return render(  8          request,  9          'blog/post_list.html', 10          {'post_list': Post.objects.all()})

We wish to list our blog posts at /blog/. However, this is already the URL path matched by our call to include in suorganizer/urls.py. When a user requests /blog/, Django will remove the root ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.