导致以下模板错误的原因是什么?
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 :(得分:2)
您在以下位置定义了site_name
:
{% blocktrans with site.name as site_name %}
Please sign in with your existing acounts
{% endblocktrans %}
你没有引用它。
但您在<:p>处引用了site_name
{% blocktrans %}
<a href="{{ signup_url }}">sign up</a> for a {{site_name}} account and sign in below:
{% endblocktrans %}
您未在开始site_name
代码时声明并定义blocktrans
。
正如我从你的追溯中看到的,django没有抱怨,因此可能会从socialaccount/snippets/provider_list.html
或socialaccount/snippets/login_extra.html
发出错误。
答案 1 :(得分:-1)
仅{% endblock %}
,而不是{% endblocktrans %}