我的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