1

idDjango テンプレートで JSON のフィールドにアクセスしようとしていますが、コロンが含まれています。

テンプレートに含めると、次のエラーが発生します。

「残りを解析できませんでした: ':id' from 'result.id.attributes.im:id'".

名前とコロンをエスケープしようとしましたが、成功しませんでした。

親を使用するときの JSON 出力と、Django テンプレートを含めました。

助言がありますか?

*親 (result.id.attribute) を渡すときの JSON を含む HTML 出力 *

1 id: {**u'im:id': u'422689480'**, u'im:bundleId': u'com.google.Gmail'} Name: Gmail - Google, Inc.

2 id: {u'im:id': u'530755375', u'im:bundleId': u'com.kfactormedia.mycalendarfree'} Name: MyCalendar Free - K-Factor Media, LLC.

3 id: {u'im:id': u'518972315', u'im:bundleId': u'com.click2mobile.textGramFree'} Name: Textgram - Texting with Instagram FREE - click2mobile

4 id: {u'im:id': u'521863802', u'im:bundleId': u'com.appmosys.emoji2free'} Name: Emoji 2 Free - 300+ NEW Emoticons and Symbols - Appmosys

Django テンプレート

<html>
<body>

{% for result in app_data.entry %}


<h3>

    {{ forloop.counter }}
    Id: {{ result.id.attributes }}
    Name: {{ result.title.label }}


{% endfor %}
</h3>
</body>
</html>

ビューを含めるように編集します。

意見

def findAppRank(request,AppId=424909112):

URL="http://itunes.apple.com/us/rss/topfreeapplications/limit=300/genre=6007/json"

r=requests.get(URL)

output=r.content
data=json.loads(output)

AppData=data['feed']

t=get_template('myrank.html')

html=t.render(Context({'app_data': AppData, 'app_id': AppId }))

return HttpResponse(html)
4

1 に答える 1

0

sliceフィルターを探しています。

{{ result.id.attributes|slice:"'im:id'" }}
于 2012-06-28T14:51:29.650 に答える