7.8.2 A URL and View for New List Creation
parent
24fb7b1e09
commit
b5ab7f620a
|
@ -1,3 +1,5 @@
|
|||
from typing import Text
|
||||
from django.http import request
|
||||
from django.shortcuts import redirect, render
|
||||
|
||||
from lists.models import Item
|
||||
|
@ -12,4 +14,8 @@ def home_page(request):
|
|||
|
||||
def view_list(request):
|
||||
items = Item.objects.all()
|
||||
return render(request, 'list.html', {'items': items})
|
||||
return render(request, 'list.html', {'items': items})
|
||||
|
||||
def new_list(request):
|
||||
Item.objects.create(text=request.POST['item_text'])
|
||||
return redirect('/lists/the-only-list-in-the-world/')
|
|
@ -18,5 +18,6 @@ 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'),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue