首页 文章

当基本模板位于根文件夹中时,TemplateDoesNotExist

提问于
浏览
1

我有以下目录:

项目

  • templates < - base.html位于此处

  • 用户< - App

  • users / templates < - profile.html位于此处

profile.html扩展了base.html . 当我试图访问它时:

return render_to_response('profile.html', {}, context_instance=RequestContext(request))

我收到TemplateDoesNotExist异常:

异常类型:TemplateDoesNotExist异常值:profile.html

Django尝试按以下顺序加载这些模板:使用loader django.template.loaders.filesystem.Loader:使用loader django.template.loaders.app_directories.Loader:... lib / python2.7 / site-packages / django / contrib / admin / templates / profile.html(文件不存在)... lib / python2.7 / site-packages / django / contrib / auth / templates / profile.html(文件不存在)... users / templates / profile.html(文件存在)

1 回答

  • 2

    通过在 app/templates 目录中添加 app 目录,更改 templates 目录结构,即 app/templates/template.htmlapp/templates/app/template.html .

    Project
    |-- users
    |   |-- models.py
    |   |-- templates
    |       `-- users
    |           `-- profile.html
    |-- templates
        `-- base.html
    

相关问题