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"
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:
Post your comments / questions
Recent Article
- The request was aborted: Could not create SSL/TLS secure channel -Error in Asp.net
- How to hide the ID field from the Django admin?
- It is impossible to add a non nullable field without specifying a default. Django error
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
Related Article