c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
Python

FieldError: Cannot resolve keyword 'id' into field in Django project

| | django , python
I got this following error while running django web application
"FieldError at /post/3/
Cannot resolve keyword 'id' into field. Choices are: description, id_category, image, name, status"FieldError

CODE:

def show_post(request, pk):

post = get_object_or_404(Post,pk=pk)
brand = Category.objects.get(id=post.category)
return render(request, 'post.html', {'post':post, 'brand':brand})

SOLUTION:

If your model uses a different name for the primary key field, you should use that name instead. For above code, I used id=post.category but primary key field is id_category. so I changed it.

brand = Category.objects.get(id_category=post.category)

VIDEO GUIDE: