django - Expected 'not' in if statement template error -
in page have voting possibility. each object can liked facebook 'like' button. if item liked, hide button. i've wrote method liked object's check if user given ip voted. ip 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 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:
{% 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> <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 raises : expected 'not' in if statement . ideas why ? adding 'not' in 'if' tag raises improperly formatted :/
your if statement in template seems missing operator.
{% if submission.get_vote ip_address %} if submission.get_vote (is the) ip_address? == perhaps?
see django template docs list of if accepts in template.
also, it's not clear ip_address is. mean remote_addr, or somehow refer ip address have already?
also, i'd suggest not using bare except:. limit exceptions thinking of specifically. not specifying exception can hide other errors. suggest adding
from django.core.exceptions import objectdoesnotexist and
except objectdoesnotexist: in check_vote method.
where check_vote called?
Comments
Post a Comment