{% trans "string" because my_translated_string%} does not display content in the template

The django 1.4 doc says that you can translate strings to "vars" to be used in different places, or used as arguments in tags or template filters using the following syntax:

{% trans "String" as my_translated_string %}

<h1>{{ my_translated_string }}</h1>

https://docs.djangoproject.com/en/1.4/topics/i18n/translation/#trans-template-tag

I do it this way, however a particular var never passes content. Below is my template code:

{% extends "default_layout.html" %}

{% load i18n %}

{% trans "My page title" as title %}

{% block meta_title %}{{ title }}{% endblock %}

{% block content %} 
    <h1>{{ title }}</h1>
{% endblock %}

Of course, the β€œname” in both cases becomes empty.

Did I miss something?

Thank.

+5
source share
1 answer

okm , , , :

{% extends "default_layout.html" %}
{% load i18n %}

{% block meta_title %}
{% trans "My page title" as title %}
{{ title }}
{% endblock %}

{% block content %}
{% trans "My page title" as title %}
    <h1>{{ title }}</h1>
{% endblock %}
+7

All Articles