7.10.1 Capturing Parameters from URLs

chap7-new
Jason Zhu 2020-11-11 14:54:17 +11:00
parent df26c82490
commit 434e66e0ae
2 changed files with 4 additions and 3 deletions

View File

@ -6,8 +6,9 @@ from lists.models import Item, List
def home_page(request): def home_page(request):
return render(request=request, template_name='home.html') return render(request=request, template_name='home.html')
def view_list(request): def view_list(request, list_id):
items = Item.objects.all() list_ = List.objects.get(id=list_id)
items = Item.objects.filter(list=list_)
return render(request, 'list.html', {'items': items}) return render(request, 'list.html', {'items': items})
def new_list(request): def new_list(request):

View File

@ -19,5 +19,5 @@ from lists import views
urlpatterns = [ urlpatterns = [
url(r'^$', views.home_page, name='home'), url(r'^$', views.home_page, name='home'),
url(r'^lists/new$', views.new_list, name='new_list'), 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'),
] ]