我正在用django框架构建一个web应用程序。在我的一个模板中,我想要将超链接指向外部URL。django blocktrans外部网址
在这个模板中,我需要两种语言,所以我决定使用django blocktrans标签。从the django documentation),我只能将内部网址作为网址。 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 %}
但是,用这个片段,我该如何放置if/else语句?到目前为止,我的想法是为每个外部链接创建视图,并将if/else语句放在blocktrans标记之前。 – zakiakhmad
有了这个片段,您不需要is/else语句,因为具有正确语言代码的网址是使用{{LANGUAGE_CODE}}动态构建的 – ferrangb