18 lines
632 B
Python
Raw Normal View History

2020-11-09 11:57:23 +11:00
from django.shortcuts import redirect, render
2020-11-09 11:16:18 +11:00
from lists.models import Item
# Create your views here
def home_page(request):
2020-11-09 11:16:18 +11:00
if request.method == 'POST':
2020-11-09 11:57:23 +11:00
Item.objects.create(text=request.POST['item_text'])
2020-11-10 23:56:56 +11:00
return redirect('/lists/the-only-list-in-the-world')
2020-11-09 11:16:18 +11:00
2020-11-09 12:22:55 +11:00
items = Item.objects.all() # get objects from database (model)
return render(request=request,
template_name='home.html',
2020-11-11 13:33:55 +11:00
context={'items': items}) # pass items into template using render
def view_list(request):
items = Item.objects.all()
return render(request, 'home.html', {'items': items})