2012-10-24 68 views
-1

我的上下文字典沒有發送到我的模板。 我有功能Django模板中沒有工作變量

from django.shortcuts import render_to_response 
from django.template import RequestContext 
def home(request): 
    return render_to_response('home.html',{'test':'test'},context_instance=RequestContext(request)) 

和我有簡單的模板,例如:

<html> 
<body> 
my test == {{test}} 
</body> 
</html> 

,當我在瀏覽器中打開我的網站,我有「我的測試==」。 settings.py是默認值。我不使用自定義的東西。什麼問題? 服務器是帶有wsgi模塊的apache。

+0

它使用內置的開發服務器中的django工作嗎? – dm03514

+0

使用'{%debug%}'模板標籤找出錯誤。 –

+0

你沒有定義什麼樣的測試是'test ='hello world',並作爲回報''test':測試'而不是'test':'test''。 – Goran

回答

0

我知道了,但我剛纔看到你的帖子。你做得很好,但你需要做更多的事情。這裏是觀點

def home(request): 
    # You need to retrieve something from the database or create a variable here 
    test = Test.Objects.all() 
    # Use Context Dic 
    context = { 
    'test': test, 
    } 
    # Then Use the return 
    return render(request, 'home.html', context) 

(編輯) 現在,這將工作。