2017-09-13 41 views
0

所以,我有PyCharm 2017.2.3和Python 3.6以及Django 1.11。在練習測試項目時,我嘗試在我的應用下呈現給我的index.htmlview.py。下面是我講的一段代碼:Django 1.11中的template.render()python子函數不可用

def index(request): 
    db_Conn = Album.objects.all() 
    template = loader.get_template('/music/index.html') 
    context = { 
     'db_Conn': db_Conn, 
    } 
    return HttpResponse(template.re) 

裏面return HttpResponse,我可以到模板,但是當我使用模板經過一段時間的使用render()子功能,我沒有得到任何建議取而代之的是來自PyCharm的render(),我可以看到兩個與我的帖子無關的其他功能。

sombody能幫我解決這個問題。由於這個原因,我的學習停止了。

+1

只是一個建議,跟進[本教程(https://開頭教程.djangogirls.org/en /)和[官方文檔](https://docs.djangoproject.com/en/1.11/) –

+2

您不應該依賴編輯器的自動完成功能。 Python是一種動態語言,靜態分析通常不起作用。按照文檔。 –

回答

0

試試這個。我認爲音樂是應用程序的名稱,所以你的模板文件應該是,music/templates/index.html

from django.shortcuts import render 
from django.utils import timezone 
def index(request):  
     return render(request, 'index.html', {'start_date':timezone.now()}) 

如果不明白請參閱本repo

+0

我所指的培訓視頻說我們不需要提供「模板」名稱,因爲Django是爲了瞭解默認情況而設計的。不知道,如果這是真的 – user3521180

+1

不要任何類型的文件,請參閱這一個https://docs.djangoproject.com/en/1.11/ – Robert