Monday, April 25, 2016

Re: FieldError: Invalid order_by arguments: ['- pub_date']

Yes, that worked. Someone better fix that mistake in the tutorial. Also the template for index.html is also wrong, by changing line 4 to

<li><a href="{{ question.id }}/"> {{ question.question_text }}</a></li>

it now works.


On Monday, April 25, 2016 at 12:42:49 PM UTC+2, Michal Petrucha wrote:
On Mon, Apr 25, 2016 at 03:28:27AM -0700, gu99...@student.chalmers.se wrote:
> I'm following the tutorials on the Django website and now I'm stuck at
> tutorial 3. I'm working on the 'polls' application.
>
> The view.py file looks like so
>
> from django.http import HttpResponse
> from django.template import loader
> from django.shortcuts import render
> from .models import Question
>
>
> def index(request):
>     *latest_question_list **= Question.objects.order_by('- pub_date')[:5]*

order_by does not allow spaces between the minus sign and field name,
if you use order_by('-pub_date'), it should work fine.

Cheers,

Michal

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/27be2793-2210-4136-a36a-f9e1a8586301%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment