2020-11-07 15:23:42 +11:00
|
|
|
from django.http.request import HttpRequest
|
|
|
|
from django.http.response import HttpResponse
|
2020-10-15 17:43:46 +11:00
|
|
|
from django.shortcuts import render
|
|
|
|
|
2020-11-09 11:16:18 +11:00
|
|
|
from lists.models import Item
|
|
|
|
|
2020-11-07 14:42:22 +11:00
|
|
|
# Create your views here
|
2020-11-07 15:23:42 +11:00
|
|
|
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 = ''
|
|
|
|
|
2020-11-08 16:50:20 +11:00
|
|
|
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
|
|
|
})
|
|
|
|
|