簡體   English   中英

如何在HTML頁面中使用Django模板訪問多維數組

[英]How to access multidimensional array using django templates in html page

我在php頁面中有一個多維數組,如下所示:

$comment=Array
(
    [655436] => 
    [655435] => Array
        (
            [id] => 5864928
            [shortmessage] => rytrht
        )

    [655434] => Array
        (
            [id] => 5864934
            [shortmessage] => vcxv
        )

    [654990] => 
    [654989] => Array
        (
            [id] => 5864948
            [shortmessage] => fgfj
        )

    [654983] => Array
        (
            [id] => 5864909
            [shortmessage] => state
        )

    [654981] => 
    [654979] => 
    [654978] => Array
        (
            [id] => 5864933
            [shortmessage] => ggjj
        )

    [654329] => Array
        (
            [id] => 5864974
            [shortmessage] => 
        )

)

echo $renderer->render('sample.html', array( 'index' => commentId,'Comment' => $comments));

我希望使用Django temlates在HTML頁面中使用$ comment數組值,而無需遍歷數組

sample.html:

<td><input class="Comment" type="text" value="{{Comment[index]['shormessage']}}" /></td>

但是{{Comment[index]['shormessage']}}沒有給出任何值,整個頁面本身也沒有顯示,我不知道如何訪問多維數組。

有什么辦法嗎?

通過以下方式使用For循環進行此嘗試

{% for Comment in Comments %}

<input class="Comment" type="text" value="{{Comment.shormessage}}" />

{%endfor%}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM