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>
                <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 :/

Answers


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?


Need Your Help

How can I change UserId in AspNet Identity Version 2 or 2.1 Alpha to an identity int

asp.net asp.net-identity

From what I can see there have been many posts asking how to do this but as the Identity code is changing very quickly I think most of the replies might be a bit dated. A quick searched showed me m...

aligning buttons on runtime

delphi user-interface runtime

I have a problem with buttons align on runtime. I want them to align in center of the panel. I have TPanel, which contains buttons that are created runtime. I want them dynamically fill the whole p...