在學習django中,render_to_response的第一個參數爲模板名稱,比如/home/yang/mysite/templates下的文件mytemp.html,第二個參數爲字典。例如:
render_to_response('mytemp.html', {'current_date':now})
在實驗中,如果想在第二個參數中放置兩個字典,比如
render_to_response('mytemp.html', {'current_date':now}, {'hour':hour_now})
此時,第二個參數將會被忽略,在生成的網頁文件中,只會出現第一個參數,要解決這個問題,可以採用字典變量。例如
dic = {'current_date':now, 'hour':hour_now}
render_to_response('mytemp.html', dic)
到此,問題解決,兩個變量均能在頁面中顯示。