19 lines
667 B
Python
Raw Normal View History

from django.http.request import HttpRequest
from django.http.response import HttpResponse
from django.shortcuts import 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':
new_item_text = request.POST['item_text'] # use new_item_text to either hold POST contents or empty string
Item.objects.create(text=new_item_text) # .object.create is shortcut for creating a new Item, without needing to call .save()
else:
new_item_text = ''
return render(request=request, template_name='home.html', context={
2020-11-08 20:39:30 +11:00
'new_item_text': request.POST.get('item_text', ''),
2020-11-09 11:16:18 +11:00
})