我想从settings.py
中的元组set_langLANGUAGES = (
('en', gettext('English'),),
('de', gettext('Germany'),),
('ru', gettext('Russian'),),
)
Urls已添加
from django.views.i18n import set_language
url(r'^setlang/', set_language, name="setlang"),
模板与lang_list有一个部分,我想set_language
{% get_available_languages as LANGUAGES %}
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<li role="presentation">
<form action="{% url "setlang" %}" method="post">
{% csrf_token %}
<button role="menuitem" tabindex="-1" type="Submit" class="btn btn-link" id="login"
value="{{ language.code }}" name="language">{{ language.code }}
({{ language.name_local }})
</button>
</form>
</li>
{% endfor %}
它给出404,并说CSRF未找到或不匹配。 “失败的原因: CSRF令牌丢失或不正确。“