如何通过下拉菜单在django模板中设置语言?

时间:2016-05-24 16:38:49

标签: python django django-templates

我想从settings.py

中的元组set_lang
LANGUAGES = (
('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令牌丢失或不正确。“

0 个答案:

没有答案