专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Perl/Python

Django的模板导入异常,小弟我没办法了。

发布时间:2011-06-29 20:10:04 文章来源:www.iduyao.cn 采编人员:星星草
Django的模板导入错误,我没办法了。。。
在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会自动寻找到
------解决方案--------------------
模板的路径最好不要用绝对路径的 相对的才是最好的引用访方法呢
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: