2016-04-11 5 views
0

Obligatorisch "Ich bin neu in Django" hier ...kann den Rest nicht analysieren: '((records_list.1.key.5)' aus '((records_list.1.key.5)'

in meinen Ansichten erschaffe ich eine Liste, genannt records_list Innerhalb dieser Liste, habe ich eine andere Liste in der Position [0] und ein Wörterbuch in der Position [1], wie folgt:.

records_list = list() 
list_one = Bet.objects.order_by('-game_date') 
list_two = {} 

im Innern des „list_two ", das ist mein Wörterbuch, ich habe einen Schlüssel, der ein Datum ist" April 2016 ", für ex, und ein Wert, der ein Tupel ist:

So kehre ich das meinem html:

records_list.append(list_one) 
records_list.append(list_two) 
return records_list 

Im html, ich möchte eine Tabelle erstellen, und ich beginnen, indem geprüft wird, ob mein Gewinn positiv ist oder nicht:

{% if records_list %} 
       <table class="table"> 
       <thead> 
        <tr> 
         <th>Date</th> 
         <th>Wins</th> 
         <th>Losses</th> 
         <th>Void</th> 
         <th>Success Rate</th> 
         <th>Return on Investment</th> 
         <th>Profit</th> 
        </tr> 
       </thead> 
       {% for key in records_list.1 %} 

        {% if ((records_list.1.key.5) > 0) %} 
         <tr class="success"> 
          <td>{{ key }}</td> 
          <td>{{ records_list.1.key.0 }}</td> 
          <td>{{ records_list.1.key.1 }}</td> 
          <td>{{ records_list.1.key.2 }}</td> 
          <td>{{ records_list.1.key.3 }}%</td> 
          <td>{{ records_list.1.key.4 }}%</td> 
          <td>{{ records_list.1.key.5 }}</td> 

         </tr> 

jedoch ich erhalte die folgenden Syntaxfehler hier:

{% if ((records_list.1.key.5) > 0) %} 

Fehler:

Could not parse the remainder: '((records_list.1.key.5)' from '((records_list.1.key.5)' 

Wenn jemand mir helfen könnte und mir in die richtige Richtung zeigen würde, würde ich mich freuen! Vielen Dank

Antwort

1

Das if-Tag unterstützt keine Klammern. Von the docs:

Use of actual parentheses in the if tag is invalid syntax. If you need them to indicate precedence, you should use nested if tags.

In Ihrem Fall sind die Klammern nicht erforderlich, so sie nur entfernen:

{% if records_list.1.key.5 > 0 %} 
+0

Ok, das war dumm. Vielen Dank! – TomasCarvalho

Verwandte Themen