Expected 'not' in if statement template error
In my page I have a voting possibility. Each object can be liked with facebook 'Like' button. If item is already liked, I would like to hide the button. So I've wrote a method for liked object's to check if user with given ip already voted. IP is stored in context variable.
def check_vote(self, ip):
id = self.id
logging.debug("id: %s, ip: %s" % (id, ip))
try:
voted = Vote.objects.get(uid=id, ip=ip)
return False
except:
logging.debug("returning True")
return True
Here's my view:
def artifact_finalists(request):
submissions = ArtifactSubmission.objects.filter(resized=True, final=True)
template_name = 'rte/artifact_finalists.html'
return render_to_response(template_name, {"submissions": submissions, 'voting': voting,}, context_instance=RequestContext(request))
And template:
{% for submission in submissions %}
<li style="float:left, width:400px, margin-right:20px">
<div class="single-submission">
<div style="float:left, margin-right:10px">
<img src="{{ submission.url100 }}" width="100px" />
</div>
<div style="float:left">
<span style="float:left">{{ submission.name }}</span>
<span style="float:left">{{ submission.description }}</span>
</div>
开发者_StackOverflow中文版 <div class="vote">
{% if submission.get_vote IP_ADDRESS %}
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="button_count" href="http://ntt.vipserv.org{{submission.get_absolute_url}}"></fb:like>
{% endif %} </div>
</div>
</li>
{% endfor %}
But it raises : Expected 'not' in if statement
. Any ideas why ? Adding 'not' in 'if' tag raises improperly formatted
:/
Your if
statement in the template seems to be missing an operator.
{% if submission.get_vote IP_ADDRESS %}
if submission.get_vote (is what to the) IP_ADDRESS? == perhaps?
See the Django template docs for a list of what if
accepts in a template.
Also, it's not clear what IP_ADDRESS is. Do you mean REMOTE_ADDR, or to somehow refer to the ip address you have already?
Also, I'd suggest not using a bare except:
. Limit it to the exceptions you are thinking of specifically. Not specifying the exception can hide other errors. I suggest adding
from django.core.exceptions import ObjectDoesNotExist
and then
except ObjectDoesNotExist:
in the check_vote method.
Where is check_vote called?
精彩评论