【发布时间】:2015-06-17 22:00:36
【问题描述】:
我正在使用 django 框架构建一个 Web 应用程序。在我的一个模板中,我想放置一个指向外部 URL 的超链接。
在这个模板中,我需要有两种语言,所以我决定使用 django blocktrans 标签。从the django documentation),我只能把 internal URL 作为 URL。 CMIIW。
如何放置我的外部 URL?
例如。这是英语的template.html。我把http://external/docs/en/作为超链接
{% blocktrans %}
Hello, how are you? <a href="http://external/docs/en/" target="new">Lorem ipsum</a>. The quick brown fox jumps over the lazy dog.
{% endblocktrans %}
而对于德语,我需要将http://external/docs/de/ 作为超链接
{% blocktrans %}
Hello, how are you? <a href="http://external/docs/de/" target="new">Lorem ipsum</a>. The quick brown fox jumps over the lazy dog.
{% endblocktrans %}
虽然 django 文档中的示例仅适用于内部 URL。
{% if LANGUAGE_CODE == 'en' %}
{% url 'views.doc.en' as urldoc %}
{% else %}
{% url 'views.doc.de' as urldoc %}
{% endif %}
{% blocktrans %}
Hello, how are you? <a href={{ urldoc }} target="new">Lorem ipsum</a>. The quick brown fox jumps over the lazy dog.
{% endblocktrans %}
【问题讨论】:
标签: python django django-templates