我的Django应用程序的结构如下TemplateDoesNotExist
home/damon/dev/me/myproject/
manage.py
/mytracker/
__init__.py
settings.py
urls.py
/monitor/
/media/
/mymonitor/
__init__.py
models.py
views.py
urls.py
/templates/
base.html
home.html
在我的.bashrc设置PYTHONPATH
为/home/damon/dev/me/myproject/
和settings.py中添加MEDIA_ROOT和template_dir模板
MEDIA_ROOT = 'home/damon/dev/me/myproject/mytracker/monitor/media'
MEDIA_URL = '/site_media/'
TEMPLATE_DIRS = (
'home/damon/dev/me/myproject/mymonitor/templates'
)
这些值
mytracker.urls.py有
url(r'',include('mymonitor.urls')),
url(r'^site_media/(?P<path>.*)$','django.views.static.serve',{'document_root':settings.MEDIA_ROOT}),
而mymonitor.urls.py有
...
url(r'^$','mymonitor.views.home',
{'template_name':'home.html',
'page_title':'Home'
},
name='home'),
..
的base.html文件由home.html的扩展
{% extends "base.html" %}
{% block content %}
Your Home
{% endblock %}
我觉得PYTHONPATH,文件一切的位置是正确done..Still我得到一个错误TemplateDoesNotExist
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.4
Exception Type: TemplateDoesNotExist
Exception Value:
[{'page_title': 'Home'}, {'csrf_token': <django...
的views.py有
def custom_render(request,context,template):
req = RequestContext(request,context)
return render_to_response(req)
def home(request,template_name,page_title):
context = {'page_title':page_title}
return custom_render(request,context,template_name)
我不明白为什么发生这种情况。我该如何诊断这个错误..?有人可以告诉我吗?
添加一个','后''家/达蒙的/ dev/ME/myproject的/ mymonitor/templates'' in TEMPLATE_DIRS' – karthikr
此外,模板结构应该是'/ templates/mymonitor/home。html' – karthikr
html文件不应该驻留在TEMPLATE_DIRS? – damon