0
votes

i use the set_language redirect view form from the docs.

urls.py

urlpatterns += patterns('',
    (r'^i18n/', include('django.conf.urls.i18n')),
)

template:

<form action="/i18n/setlang/" method="post">
{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}" />
<select name="language">
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}">{{ language.name_local }} ({{ language.code }})</option>
{% endfor %}
</select>
<input type="submit" value="Go" />
</form>

Which is the right syntax to replace the action attribute "/i18n/setlang/" with the url-template-tag?

EDIT:

I found the right url in the include (thanks to Daniel!):

<form action="{% url django.views.i18n.set_language %}" method="post">
2

2 Answers

1
votes

As the documentation says, you can enter the full path of a view as the {% url %} parameter

{% url django.views.i18n.set_language %} # quote or unquote based on your Django version
0
votes

You don't care about the URL of the include, you care about the URLs inside the include. You should look at the code or the documentation for django.conf.urls.i18n to find the setlang URL you are interested in, and use that name.