everything's cool? It's my first question, english is not my native language so please take it easy on me hahahaha
Ok, so here is the problem, I believe it's a ident... idk how to say it in english but anyway, structural problem.
What's happening: I'm learning following the tutorial and in my localhost website almost everything is running clean but when I decide to "vote" on a "Question", it leads to a error page.
Here's the traceback (the final line):
django.template.exceptions.TemplateSyntaxError: 'for' statements should have at least four words: for choice question_set.all
and where the error (I believe) is placed, my "/results.html" file:
<h1>{{ question.question_text }}</h1>
<ul>
{% for choice question_set.all %}
<li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{
choice.votes|pluralize }}</li>
{% endfor %}
</ul>
<a href="{% url 'polls:detail' question.id %}">Vote again?</a>
My models.py code (as asked <3):
from django.db import models
import datetime
from django.utils import timezone
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField ('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
now = timezone.now()
return now - datetime.timedelta(days=1) <= self.pub_date <= now
was_published_recently.admin_order_field = 'pub_date'
was_published_recently.boolean = True
was_published_recently.short_description = 'Published recently?'
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text
Thanks for everything! hope it's understandable. (:
You've just forgotten the statement in
{% for choice in question_set.all %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With