2016-11-10 52 views
0

我有以下代碼:Django的形式:錯誤顯示

  {% if form.errors %} 
       <div class="alert alert-danger" role="alert"> 
        <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> 
        <span class="sr-only">Error:</span> 
        {{ form.errors }} 
       </div> 
      {% endif %} 

這產生如下:

error picture

我想刪除的要點,而不是包括__所​​有__部分。

任何幫助將不勝感激,非常感謝,艾倫。

櫃面它可能有助於形式的清潔部分如下:

def clean(self): 
    cleaned_data = self.cleaned_data # individual field's clean methods have already been called 
    team1 = cleaned_data.get("team1") 
    team2 = cleaned_data.get("team2") 
    if team1 == team2: 
     raise forms.ValidationError("You picked the same team!") 

    return cleaned_data 

回答

0

你可以嘗試做這樣的事情:

{% if form.errors %} 
    {% for error in form.errors %} 
     <div class="alert alert-danger" role="alert"> 
      <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> 
      <span class="sr-only">Error:</span> 
      {{ error }} 
     </div> 
    {% endfor %} 
{% endif %} 

我認爲,應該工作。你有什麼輸出?