基本模板在根文件夹中时,TemplateDoesNotExist [英] TemplateDoesNotExist when base template is in root folder

查看:750
本文介绍了基本模板在根文件夹中时,TemplateDoesNotExist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下目录:

项目


  • 模板< - base.html位于这里

  • templates <-- base.html located here

users< - App

users <-- App

- users / templates< - profile.html位于这里

-- users/templates <-- profile.html located here

profile.html extends base.html。当我尝试访问它时:

profile.html extends base.html. And when I'm trying to access it:

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

我得到TemplateDoesNotExist异常:

I'm getting TemplateDoesNotExist exception:

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

Exception Type: TemplateDoesNotExist Exception Value: 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(文件存在)

Django tried loading these templates, in this order: Using loader django.template.loaders.filesystem.Loader: Using loader django.template.loaders.app_directories.Loader: ...lib/python2.7/site-packages/django/contrib/admin/templates/profile.html (File does not exist) ...lib/python2.7/site-packages/django/contrib/auth/templates/profile.html (File does not exist) ...users/templates/profile.html (File exists)


推荐答案

将您的模板目录结构更改为 app / templates / template.html A通过在应用/模板应用程序目录,pp / templates / app / template.html c>目录。

Change your templates directory structure, That is app/templates/template.html to app/templates/app/template.html by adding an app directory inside the app/templates directory.

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

这篇关于基本模板在根文件夹中时,TemplateDoesNotExist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆