From 434e66e0ae645e90cf4b03d4f215ae68a97ebc4a Mon Sep 17 00:00:00 2001 From: JasonHomeWorkstationUbuntu Date: Wed, 11 Nov 2020 14:54:17 +1100 Subject: [PATCH] 7.10.1 Capturing Parameters from URLs --- src/lists/views.py | 5 +++-- src/superlists/urls.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lists/views.py b/src/lists/views.py index 77cc557..c35c7d8 100644 --- a/src/lists/views.py +++ b/src/lists/views.py @@ -6,8 +6,9 @@ from lists.models import Item, List def home_page(request): return render(request=request, template_name='home.html') -def view_list(request): - items = Item.objects.all() +def view_list(request, list_id): + list_ = List.objects.get(id=list_id) + items = Item.objects.filter(list=list_) return render(request, 'list.html', {'items': items}) def new_list(request): diff --git a/src/superlists/urls.py b/src/superlists/urls.py index 711ddeb..5a673b6 100644 --- a/src/superlists/urls.py +++ b/src/superlists/urls.py @@ -19,5 +19,5 @@ from lists import views urlpatterns = [ url(r'^$', views.home_page, name='home'), url(r'^lists/new$', views.new_list, name='new_list'), - url(r'^lists/the-only-list-in-the-world/$', views.view_list, name='view_list'), + url(r'^lists/(.+)/$', views.view_list, name='view_list'), ]