2010-03-25 75 views
0

我需要動態地生成這樣的代碼生成的HTML搞清楚動態菜單生成:需要幫助在Django

<p>>> gallery one</p> 
<p><a href="../gallery2">gallery two</a></p> 
<p><a href="../about">about the author</a></p> 
<p><a href="../news">our news</a></p> 

我確實有views.py創建menu_code字符串變量(它產生取決於傳遞的當前頁面的項目編號 - 在上述情況下爲1),其中包含具有上述代碼的長字符串。這是(很好,應該)由當地人()到HTML模板傳遞(所有其它變量都通過這種方式成功):

return render_to_response('gallery_page.html', locals()) 

我有這樣的:

{% include menu_code %} 

模板HTML裏面。但不是被解釋爲代碼,它只是在瀏覽器中顯示爲文本。

我在做什麼錯?如何使它作爲一個動態生成的菜單工作?

回答

0

原來有必要圍繞線路在模板與autoescape這樣的:

{% autoescape off %} 
{{ menu_code }} 
{% endautoescape %}