16 lines
608 B
Python
Raw Normal View History

from django.http.request import HttpRequest
from django.http.response import HttpResponse
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',
context={'items': items}) # pass items into template using render