2013-02-19 11 views
5

मैं अपने Django html पृष्ठ में निम्न कार्य करने के:Django 'अगर और' टेम्पलेट

{% if myList|length and ifequal myValue 'somestring' %} 
blah blah 
{% endif %} 

लेकिन मैं त्रुटि मिलती है: के अंत में अप्रयुक्त 'myValue' अगर अभिव्यक्ति

मैं एक टेम्पलेट में अगर और कैसे कर सकता हूं ??

उत्तर

0

मुझे लगता है कि यदि आप दो कथन में if और ifequal अलग करने के लिए हो सकता है:

{% if myList|length %} 
    {% ifequal myValue 'somestring' %} 
      blah blah 
    {% endifequal %} 
{% endif %} 
12

कुछ इस तरह होना चाहिए:

{% if myList|length and myValue == 'somestring' %} 
    blah blah 
{% endif %} 
+0

आपके जैसा ही उपयोग करें। मुझे लगता है कि मैं पार्टी के लिए देर हो चुकी हूँ। – arulmr

+0

@arulmr दो मिनट देर से लेकिन एक वोट आगे :) – kmerenkov

+0

क्षमा करें दोस्त। यह सिर्फ एक संयोग है। – arulmr

15

आज़माएं:

{% if myList|length and myValue == 'somestring' %} 
    blah blah 
{% endif %} 

boolean-operators और उपयोग के बारे में django दस्तावेज़ीकरण का संदर्भ लें Django टेम्पलेट्स में complex-expressions

0

Django docs on boolean operators

Should be something like this

  1. view.py
def posts_request(request): 
    message=ApplyPost.objects.filter(blah blah) 
    if message: 
     return render (request,'blah.html',{'message':message}) 
  1. blah.html
{% if message %} 
    {% for post in message %} 
      {% if post.provider %} 
       .... 
      {% endif %} 
      {% if post.accept == True and post.provider %} 
       ... 
       ... 
      {% endif %} 
      ....You can add multiple if,elif, with Operators .... 
    {% endfor %} 
{% if message %} 

and

{% if a == b or c == d and e %} 

कि ध्यान रखें और से या पूर्वता के एक उच्च आदेश है, और वह कोष्ठकों संभव नहीं हैं। यदि आवश्यक हो तो नेस्टेड ब्लॉक

संबंधित मुद्दे