在C:\Python26\Lib\site-packages\django\conf\project_template\settings.py中路径添加了绝对路径:
- Python code
TEMPLATE_DIRS = ('C:/Django-1.3.1/django/bin/mysite/templates',)
VIEW:
- Python code
def NBA(request): t = get_template('nba.html') c = Context({'arg':'the Greatest Basketball Player'}) return HttpResponse(t.render(c))
URL:
- Python code
urlpatterns = patterns('',url(r'^nba/$',NBA))
错误提示如下:
- HTML code
TemplateDoesNotExist at /nba/ nba.htmlRequest Method: GET Request URL: http://127.0.0.1:8000/nba/ Django Version: 1.3.1 Exception Type: TemplateDoesNotExist Exception Value: nba.html Exception Location: C:\Python26\Lib\site-packages\django\template\loader.py in find_template, line 138 Python Executable: C:\python26\python.exe Python Version: 2.6.0 Python Path: ['C:\\Django-1.3.1\\django\\bin\\mysite', 'C:\\python26\\python26.zip', 'C:\\python26\\DLLs', 'C:\\python26\\lib', 'C:\\python26\\lib\\plat-win', 'C:\\python26\\lib\\lib-tk', 'C:\\python26', 'C:\\python26\\lib\\site-packages', 'C:\\python26\\lib\\site-packages\\win32', 'C:\\python26\\lib\\site-packages\\win32\\lib', 'C:\\python26\\lib\\site-packages\\Pythonwin'] Server time: Fri, 18 Nov 2011 17:01:59 +0800 Template-loader postmortem Django tried loading these templates, in this order: Using loader django.template.loaders.filesystem.Loader: Using loader django.template.loaders.app_directories.Loader
------解决方案--------------------
在你的app下建个文件夹名叫templates,把你的模板放进去,django会自动寻找到
------解决方案--------------------
模板的路径最好不要用绝对路径的 相对的才是最好的引用访方法呢