Im new to Django Framework and i'm taking an online course on LinkedIn Learning. I am using a newer version of python/django so I run into some syntax problems.
my python version is 3.5.4rc1. my django version is 1.11.4
I created a model in models.py for an inventory:
class Item(models.Model):
titel = models.CharField(max_length=200)
omschrijving = models.TextField()
aantal = models.IntegerField()
This is the code in my views.py file:
from django.shortcuts import render
from django.http import Http404
from inventory.models import Item
def index(request):
items = Item.objects.exclude(aantal=0)
return render (request, 'inventory/index.html', {
'items': items,
})
return HttpResponse('<p>In index view</p>')
def item_detail(request, id):
try:
item = Item.objects.get.id=(id) #THIS ONE CAUSES PROBLEM???
except Item.DoesNotExist:
raise Http404('Dit item bestaat niet')
return render(request, 'inventory/item_detail.html', {
'item': item,
})
In the browser the localhost:8000 shows homepage as expected. localhost:8000/item/1/ gives error:
AttributeError at /item/1/
'method' object has no attribute 'id'
Request Method: GET
Request URL: http://localhost:8000/item/1/
Django Version: 1.11.4
Exception Type: AttributeError
Exception Value:
'method' object has no attribute 'id'
Exception Location:
C:\Users\info_000\Desktop\django\mysite\inventory\views.py in item_detail, line 15
Please Help!