PurePhoenix PurePhoenix - 1 year ago 89
Python Question

Django "Cannot resolve keyword" error. Can someone explain this?

I am just begining to learn how to use django. I am comming up with this error in my CLI

File "C:\Python27\Lib\site-packages\django\db\models\sql\query.py", line 1337,
in setup_
"Choices are: %s" % (name, ", ".join(names)))
FieldError: Cannot resolve keyword 'likes' into field. Choices are: id, name,

My problem is that I don't know what it means or how to fix it. Can someone please explain?
This is the output that the debugger log gave me:

Error during template rendering

In template C:\Users\aharon\Desktop\TEMP\index.html, error at line 40
Cannot resolve keyword 'likes' into field. Choices are: id, name, page
30 </html>
32 <html>
33 <head>
34 <title>Rango</title>
35 </head>
37 <body>
38 <h1>Rango says...hello world!</h1>
40 {% if categories %} <--this was highlighted in the debugger
41 <ul>
42 {% for category in categories %}
43 <li>{{ category.name }}</li>
44 {% endfor %}
45 </ul>
46 {% else %}
47 <strong>There are no categories present.</strong>
48 {% endif %}
50 <a href="/rango/about/">About</a>

View code:

from django.http import HttpResponse
from django.template import RequestContext
from django.shortcuts import render_to_response
from rango.models import Category

def index(request):
context = RequestContext(request)

category_list = Category.objects.order_by('-likes')[:5]
context_dict = {'categories': category_list}

return render_to_response('index.html', context_dict, context)

Answer Source

The issue is caused by the following line:

category_list = Category.objects.order_by('-likes')[:5]

It appears that Category model has no field likes, but id, name and page.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download