2012-07-01 11 views
6

testlistはオブジェクトのリストです。例えばテンプレートでフィルタを使用しようとすると、TemplateSyntaxErrorが発生する

testlist.0.name 

は、私はそこtemp.htmlファイル内にあり、base.htmlがすべてで正常に動作し、すべてのファイルtemp.html

{% extends 'base.html' %} 
{% block content %} 
{{testlist.0.name | safe}} 
{% endblock %} 

を持って、単に "Test3は"

ですそれを使用する他のHTMLファイル

temp.htmlは私に

TemplateSyntaxError at /mytests/ 
Could not parse the remainder: ' | safe' from 'testlist.0.name | safe' 
Request Method: GET 
Request URL: http://127.0.0.1:8000/mytests/ 
Django Version: 1.4 
Exception Type: TemplateSyntaxError 
Exception Value:  
Could not parse the remainder: ' | safe' from 'testlist.0.name | safe' 
を与えます

私はそれを変更する場合:

{% extends 'base.html' %} 
{% block content %} 
{{testlist.0.lastedited |date:"SHORT_DATE_FORMAT" }} 
{% endblock %} 

それはあなたのアイデアを得る私に

TemplateSyntaxError at /mytests/ 
could not parse some characters: testlist.0.lastedited| ||date:"SHORT_DATE_FORMAT" 
Request Method: GET 
Request URL: http://127.0.0.1:8000/mytests/ 
Django Version: 1.4 
Exception Type: TemplateSyntaxError 
Exception Value:  
Could not parse some characters: testlist.0.lastedited| ||date:"SHORT_DATE_FORMAT" 

を与えます。私はちょうど私のdjangoテンプレートでフィルタを使用することはできないようです。私は他のフィルターを試して、同じことをやっています。 パイプ文字を使用できるいくつかのオプションがありませんか?それは "|"私のmacbook proのキーはパイプ文字ではなく、djangoが認識できない他の文字ですか?

答えて

9

testlist.0.lasteditedとフィルタの間の空白を削除する必要があるようです。ドキュメントでは、彼らは任意の空白を持っていない、と彼らは文字列またはそれに近いものとして、テンプレートを解析し、その空白ができるので、私は、これはあなたの問題です推測している

{% extends 'base.html' %} 
{% block content %} 
{{testlist.0.name|safe}} 
{% endblock %} 

:ような何かを試してみてくださいそれに影響を与える。

Template example

+0

これはありがとうございました。それは1時間私を夢中にされた – panosmm

+1

さて、それを行う方法を考え出した、もう一度ありがとう。私はこれで新しいです:) – panosmm

関連する問題