2013-03-21 32 views
2

什麼是導致以下模板錯誤?什麼導致了以下模板錯誤'無效塊標記:'blocktrans',預計'elif','else'或'endif'?

In template /var/www/userreg/tagging/templates/registration/login.html, error at line 153 

Invalid block tag: 'blocktrans', expected 'elif', 'else' or 'endif' 
    143 : 
    144 : 
    145 : <td> 
    146 : 
    147 : </td> 
    148 : </tr> 
    149 : </table> 
    150 : </td> 
    151 : <td style="text-align:center;"> 
    152 :  {% if socialaccount.providers %} 
    153 : <p> {% blocktrans with site.name as site_name %} Please sign in with your 
existing acounts through {% endblocktrans %} 
    154 : 
    155 : <div class="socialaccount_ballot"> 
    156 : 
    157 : <ul class="socialaccount_providers"> 
    158 :  {% include "socialaccount/snippets/provider_list.html" %} 
    159 : </ul> 
    160 : 
    161 : <div class="login-or">{% trans 'or' %}</div> 
    162 : 
    163 : </div> 
Exception Type: TemplateSyntaxError at /accounts/login/ 
Exception Value: Invalid block tag: 'blocktrans', expected 'elif', 'else' or 'endif' 

環境:

Request Method: GET 
Django Version: 1.5 
Python Version: 2.7.3 

安裝的應用程序:

('django.contrib.auth', 
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.sites', 
'django.contrib.messages', 
'django.contrib.staticfiles', 
'django.contrib.admin', 
'registration', 
'django.contrib.humanize', 
'allauth', 
'allauth.account', 
'allauth.socialaccount', 
'allauth.socialaccount.providers.facebook', 
'allauth.socialaccount.providers.google', 
'allauth.socialaccount.providers.linkedin') 

安裝中間件:

('django.middleware.common.CommonMiddleware', 
'django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware') 

我的模板

{% extends "base.html" %} 

{% load i18n %} 
{% load account %} 
{% load url from future %} 

{% block title %}Log in{% endblock %} 

{% block content_header %}Log in{% endblock %} 

{% block main_content %}  
    {% if socialaccount.providers %}  
    <p> 
     {% blocktrans with site.name as site_name %} 
     Please sign in with your existing acounts through  
     {% endblocktrans %} 

     <div class="socialaccount_ballot"> 
      <ul class="socialaccount_providers"> 
      {% include "socialaccount/snippets/provider_list.html" %}  
      </ul> 

      <div class="login-or">{% trans 'or' %}</div> 
     </div> 

     {% include "socialaccount/snippets/login_extra.html" %} 

     {% blocktrans %}  
     <a href="{{ signup_url }}">sign up</a> for a {{site_name}} account and sign in below: 
     {% endblocktrans %} 
    </p> 
    {% endif %}   
{% endblock %} 
+0

發佈標記(模板),以及例外......這就是我們所需要的。 – Nix 2013-03-21 12:38:33

+0

下次請自行格式化您的問題。我也想知道這是不是太本地化。 – Private 2013-03-21 12:45:47

+0

看來,如果你在第152行它沒有關閉(基於我所看到的)。也許你應該嘗試在末尾添加{%endif%} – 2013-03-21 12:40:19

回答

-1

只是{% endblock %},不{% endblocktrans %}

+0

如果我單獨給出{%endblock%},它會給出更多的錯誤,如下所示:TemplateSyntaxError at/accounts/login/ 'blocktrans'不允許其他塊標籤(看到u'endblock')裏面 – Mathi 2013-03-21 13:19:51

+0

你是對的,我的錯誤。檢查先前的答案。他想說,在關閉第一個程序塊轉換之後,您不能使用site_name。當你使用它時,你必須重新定義它。把所有東西都放在一個blocktrans中,而不是兩個。 – Tamara 2013-03-21 14:09:06

1

您在定義site_name

{% blocktrans with site.name as site_name %} 
    Please sign in with your existing acounts 
{% endblocktrans %} 

如果你沒有提到它。

但你在引用site_name

{% blocktrans %} 
    <a href="{{ signup_url }}">sign up</a> for a {{site_name}} account and sign in below: 
{% endblocktrans %} 

如果你沒有申報,並在開幕blocktrans標籤定義site_name

從我的回溯中可以看出,django沒有投訴,所以錯誤可能從socialaccount/snippets/provider_list.htmlsocialaccount/snippets/login_extra.html發出。

相關問題