FieldError at /polls/ Cannot resolve keyword '' into field. Choices are: choice, id, pub_dte, question_text

I just started part 6. When I run the server I get an error page that starts with ``` FieldError at /polls/

Cannot resolve keyword ‘’ into field. Choices are: choice, id, pub_dte, question_text … Raised during: polls.views.IndexView ``` Here is my polls.views.IndexView

from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
from django.views import generic
from django.utils import timezone

from .models import Choice, Question

class IndexView(generic.ListView):
   template_name = "polls/index.html"
   context_object_name =  "latest_question_list"
       
   def get_queryset(self):
       # ***Return thee last five published questions***
       # return Question.objects.order_by("-pub_dte")[:5]
       return Question.objects.filter(pub_dte__lte=timezone.now()).order_by("")



class DetailView(generic.DetailView):
       model = Question
       template_name = "polls/detail.html" 

       def get_queryset(self):
            """ 
            Excludes any questions that aren't published yet
            """
            return Question.objects.filter(pub_dte__lte=timezone.now())


       
class ResultsView(generic.DetailView):
       model = Question
       template_name = "polls/results.html" 
       

def vote(request, question_id):
   question = get_object_or_404(Question, pk=question_id)
   try:
        selected_choice = question.choice_set.get(pk=request.POST["choice"])
   except (KeyError, Choice.DoesNotExist):
        #Redisplay the question voting form
        return render(request, "polls/detail.html", {
             "question": question,
             "error_message": "You didn't select a choice. Please choose one and select!",
        },)
   else:
        selected_choice.votes = F("votes") + 1
        selected_choice.save()
       #  # Always return an HttpResponseRedirect after successfully dealing
       # with POST data. This prevents data from being posted twice if a
       # user hits the Back button
   return HttpResponseRedirect(reverse("polls:results", args=(question.id, )))```

Which line did it flag with that error?

(You should have gotten a complete traceback in your console for that error. Please post that traceback.)

Let me check and see which line.

Honestly I don’t know how to check which line was flagged. Sometimes in the error page I am given the line where the error occurs(in red). But on this page I just get alot of info. Is this what you are asking for? Exception Location: C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\db\models\sql\query.py, line 1768, in names_to_path

That “info” is the traceback - it’s a lot of useful information for you to use to help determine the cause of an error.

Yes, that’s one line from it. If you post the entire traceback, I can highlight what you want to look for.

Okay. Here it is ```
FieldError at /polls/

Cannot resolve keyword ‘’ into field. Choices are: choice, id, pub_dte, question_text

Request Method: GET
Request URL: http://127.0.0.1:8000/polls/
Django Version: 5.1
Exception Type: FieldError
Exception Value:

Cannot resolve keyword ‘’ into field. Choices are: choice, id, pub_dte, question_text

Exception Location: C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\db\models\sql\query.py, line 1768, in names_to_path
Raised during: polls.views.IndexView
Python Executable: C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Scripts\python.exe
Python Version: 3.12.5
Python Path:

[‘C:\Users\hp\Documents\Learn Python\Django\mdn04\mysite’,
'C:\Program ’
‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0\python312.zip’,
'C:\Program ’
‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0\DLLs’,
'C:\Program ’
‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0\Lib’,
'C:\Program ’
‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0’,
‘C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04’,
'C:\Users\hp\Documents\Learn ’
‘Python\Django\mdn04\venmdn04\Lib\site-packages’]

Server time: Tue, 20 Aug 2024 19:57:24 +0000
Traceback Switch to copy-and-paste view

Ok, that’s what’s showing up in your browser, not in your server console where you’re running runserver. It’s the contents of that window that contains the full traceback.
That’s what you should be looking at.

Let me understand. Do you mean I should get the traceback from the terminal in Vscode?

Wherever it is that you are running runserver.

Is this what I should be posting? ```
(venmdn04) C:\Users\hp\Documents\Learn Python\Django\mdn04>cd mysite

(venmdn04) C:\Users\hp\Documents\Learn Python\Django\mdn04\mysite>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks…

System check identified no issues (0 silenced).
August 20, 2024 - 21:32:38
Django version 5.1, using settings ‘mysite.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

Not Found: /
[20/Aug/2024 21:32:43] “GET / HTTP/1.1” 404 2306
Not Found: /favicon.ico
[20/Aug/2024 21:32:43,486] - Broken pipe from (‘127.0.0.1’, 52733)

There should be a traceback associated with that error.

If you just restarted runserver, then you need to cause the error to occur.

Okay. I restarted the server and went to localhost:8000/polls/. This is what I now get ```
FieldError at /polls/

Cannot resolve keyword ‘’ into field. Choices are: choice, id, pub_dte, question_text

Request Method: GET
Request URL: http://127.0.0.1:8000/polls/
Django Version: 5.1
Exception Type: FieldError
Exception Value:

Cannot resolve keyword ‘’ into field. Choices are: choice, id, pub_dte, question_text

Exception Location: C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\db\models\sql\query.py, line 1768, in names_to_path
Raised during: polls.views.IndexView
Python Executable: C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Scripts\python.exe
Python Version: 3.12.5
Python Path:

[‘C:\Users\hp\Documents\Learn Python\Django\mdn04\mysite’,
'C:\Program ’
‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0\python312.zip’,
'C:\Program ’
‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0\DLLs’,
'C:\Program ’
‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0\Lib’,
'C:\Program ’
‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.1520.0_x64__qbz5n2kfra8p0’,
‘C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04’,
'C:\Users\hp\Documents\Learn ’
‘Python\Django\mdn04\venmdn04\Lib\site-packages’]

Server time: Tue, 20 Aug 2024 20:40:22 +0000
Traceback Switch to copy-and-paste view

C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\core\handlers\exception.py, line 55, in inner

                    response = get_response(request)
                                   ^^^^^^^^^^^^^^^^^^^^^

     …
Local vars
C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\core\handlers\base.py, line 197, in _get_response

                    response = wrapped_callback(request, *callback_args, **callback_kwargs)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

     …
Local vars
C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\views\generic\base.py, line 104, in view

                return self.dispatch(request, *args, **kwargs)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

     …
Local vars
C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\views\generic\base.py, line 143, in dispatch

            return handler(request, *args, **kwargs)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

     …
Local vars
C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\views\generic\list.py, line 154, in get

            self.object_list = self.get_queryset()
                                    ^^^^^^^^^^^^^^^^^^^

     …
Local vars
C:\Users\hp\Documents\Learn Python\Django\mdn04\mysite\polls\views.py, line 17, in get_queryset

            return Question.objects.filter(pub_dte__lte=timezone.now()).order_by("")
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

     …
Local vars
C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\db\models\query.py, line 1701, in order_by

            obj.query.add_ordering(*field_names)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

     …
Local vars
C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\db\models\sql\query.py, line 2249, in add_ordering

                    self.names_to_path(item.split(LOOKUP_SEP), self.model._meta)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

     …
Local vars
C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\db\models\sql\query.py, line 1768, in names_to_path

                        raise FieldError(
                              ^

     …
Local vars

Request information
USER

zacamata```

Again, I do not want the error from the browser. Copy / paste the traceback from the runserver console.

I copied this from the terminal where I typed runserver

(venmdn04) C:\Users\hp\Documents\Learn Python\Django\mdn04\mysite>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
August 20, 2024 - 21:39:10
Django version 5.1, using settings 'mysite.settings' 
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

Not Found: /
[20/Aug/2024 21:39:30] "GET / HTTP/1.1" 404 2306
Not Found: /favicon.ico
[20/Aug/2024 21:39:30,318] - Broken pipe from ('127.0.0.1', 52760)
Internal Server Error: /polls/
Traceback (most recent call last):
 File "C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner    
   response = get_response(request)
              ^^^^^^^^^^^^^^^^^^^^^
 File "C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
   response = wrapped_callback(request, *callback_args, **callback_kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\views\generic\base.py", line 104, in view
   return self.dispatch(request, *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\views\generic\base.py", line 143, in dispatch     
   return handler(request, *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\views\generic\list.py", line 154, in get
   self.object_list = self.get_queryset()
                      ^^^^^^^^^^^^^^^^^^^
 File "C:\Users\hp\Documents\Learn Python\Django\mdn04\mysite\polls\views.py", line 17, in get_queryset
   return Question.objects.filter(pub_dte__lte=timezone.now()).order_by("")
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\db\models\query.py", line 1701, in order_by
   obj.query.add_ordering(*field_names)
 File "C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\db\models\sql\query.py", line 2249, in add_ordering
   self.names_to_path(item.split(LOOKUP_SEP), self.model._meta)
 File "C:\Users\hp\Documents\Learn Python\Django\mdn04\venmdn04\Lib\site-packages\django\db\models\sql\query.py", line 1768, in names_to_path
   raise FieldError(
django.core.exceptions.FieldError: Cannot resolve keyword '' into field. Choices are: choice, id, pub_dte, question_text
[20/Aug/2024 21:40:22] "GET /polls/ HTTP/1.1" 500 98764
Not Found: /favicon.ico
[20/Aug/2024 21:40:22,376] - Broken pipe from ('127.0.0.1', 52764)

Great! The place to start is the last entry in the traceback showing code that you have written. In this case it’s this:

Now, compare this line with what the tutorial shows what you should have, and find the difference between the two - that’s the error.

@KenWhitesell, God bless you. I am not a religious person. I don’t go to church. But man you are awesome. I just learnt something new. Thank you for your patience. I will go back to my code and make the corrections

Awesome awesome awesome. Thank you Ken, You did it. You helped me. Thank you