django中找不到模板

use*_*451 1 django django-templates

我正在使用django 1.4

Django尝试按以下顺序加载这些模板:

Using loader django.template.loaders.filesystem.Loader:
    /home/user/mysite/template/<WSGIRequest path:/polls/what/, GET:<QueryDict: {}>, POST:<QueryDict: {}>,
Run Code Online (Sandbox Code Playgroud)

使用pwd我看到这个:

/home/user/mysite/template
Run Code Online (Sandbox Code Playgroud)

template I have民意调查中

这就是我的意思 settings.py

TEMPLATE_DIRS = (
    '/home/user/mysite/template',
Run Code Online (Sandbox Code Playgroud)

现在在我看来:

return render_to_response(request, 'polls/index.html',
Run Code Online (Sandbox Code Playgroud)

为什么还在抱怨?

谢谢.

Mar*_*ius 6

这可能不是您唯一的问题,但render_to_response首先采用模板名称,然后采用上下文和上下文实例.

试试这个

from django.template import RequestContext

def view_name(request):
    # view code 
    return render_to_response('polls/index.html',
                               context_instance=RequestContext(request))
Run Code Online (Sandbox Code Playgroud)

或者,如评论中所建议的,您打算使用render快捷方式:

from django.shortcuts import render

def view_name(request):
    # view code 
    return render(request, 'polls/index.html')
Run Code Online (Sandbox Code Playgroud)

还要确保在模板中的民意调查中有一个名为index.html的模板

myapp/
    myapp/
        ...
        settings.py
        template/
            polls/
                index.html
Run Code Online (Sandbox Code Playgroud)