I am still working on the tutorial from Code with Stein. video timestamp 1:51:39. When I save my code and open my browser I get this error message
File "C:\Users\hp\Documents\Learn Python\Django\Code with Stein\Puddle\puddle\item\views.py", line 10, in items
category_id = request.Get.get('category', 0)
^^^^^^^^^^^
I compared my views.py file with the views.py file from the GitHub repo. Seemingly to my untrained eye, the code looks the same. But I still get the error.
This is my views.py file
from django.contrib.auth.decorators import login_required
from django.db.models import Q
from django.shortcuts import render, get_object_or_404, redirect
from .forms import NewItemForm, EditItemForm
from .models import Category, Item
def items(request):
query = request.GET.get('query', '')
category_id = request.Get.get('category', 0)
categories = Category.objects.all()
items = Item.objects.filter(is_sold=False)
if category_id:
items = items.filter(category_id=category_id)
if query:
items = items.filter(Q(name__icontains=query) | Q(description__icontains=query))
return render(request,'item/items.html', {
'items': items,
'query': query,
'categories': categories,
'category_id': int(category_id)
})
def detail(request, pk):
item = get_object_or_404(Item, pk=pk)
related_items = Item.objects.filter(category=item.category, is_sold=False).exclude(pk=pk)[0:3]
return render(request, 'item/detail.html', {
'item': item,
'related_items': related_items
})
@login_required
def new(request):
if request.method == 'POST':
form = NewItemForm(request.POST, request.FILES)
if form.is_valid():
item = form.save(commit=False)
item.created_by = request.user
item.save()
return redirect('item:detail', pk=item.id)
else:
form = NewItemForm()
return render(request, 'item/form.html', {
'form': form,
'title': 'New Item',
})
@login_required
def edit(request, pk):
item = get_object_or_404(Item, pk=pk, created_by=request.user)
if request.method == 'POST':
form = EditItemForm(request.POST, request.FILES, instance=item)
if form.is_valid():
form.save()
return redirect('item:detail', pk=item.id)
else:
form = EditItemForm(instance=item)
return render(request, 'item/form.html', {
'form': form,
'title': 'Edit item',
})
@login_required
def delete(request, pk):
item = get_object_or_404(Item, pk=pk, created_by=request.user)
item.delete()
return redirect('dashboard:index')