我的 django 应用程序的结构如下
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,文件位置一切都正确完成..我仍然收到 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)
我无法弄清楚为什么会发生这种情况。如何诊断此错误..?有人可以告诉我吗?