python django http://127.0.0.1:8000 打开后出现下面的错误提示

cndeer 2012-03-15 05:06:58
http://127.0.0.1:8000 打开后出现下面的错误提示

请问这是哪里的错误。找了半天也没有发现问题。有朋友说是模板不存在。。路径映射有问题。也没看出哪里不对来?

下面给出主要的文件的代码与出错提示:

TemplateDoesNotExist at /
users/index.htmlRequest Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.3.1
Exception Type: TemplateDoesNotExist
Exception Value: users/index.html
Exception Location: F:\Python27\lib\site-packages\django\template\loader.py in find_template, line 138
Python Executable: F:\Python27\python.exe
Python Version: 2.7.2
Python Path: ['F:\\Python27\\Django-1.3.1\\Django-1.3.1dasf\\django\\bin\\Django_Pro',
'F:\\Python27\\Lib\\site-packages\\wx-2.8-msw-unicode\\wxPython',
'C:\\WINDOWS\\system32\\python27.zip',
'F:\\Python27\\DLLs',
'F:\\Python27\\lib',
'F:\\Python27\\lib\\plat-win',
'F:\\Python27\\lib\\lib-tk',
'F:\\Python27',
'F:\\Python27\\lib\\site-packages',
'F:\\Python27\\lib\\site-packages\\win32',
'F:\\Python27\\lib\\site-packages\\win32\\lib',
'F:\\Python27\\lib\\site-packages\\Pythonwin',
'F:\\Python27\\lib\\site-packages\\wx-2.8-msw-unicode']
Server time: Thu, 15 Mar 2012 17:05:14 +0800




这是url
from django.conf.urls.defaults import patterns, include, url

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()

urlpatterns = patterns('',
# Examples:
(r'^$', 'Django_Pro.Users.views.index'),
#url(r'^Django_Pro/', include('Django_Pro.foo.urls')),

# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
# url(r'^admin/', include(admin.site.urls)),
)




这是:根目录下users 里的views.py文件
#-*- coding:utf-8 -*-
from django.shortcuts import render_to_response
from Django_Pro.Users.models import Users
def index(rq):
#获取Users数据模型对应表中的数据
latest_users_list = Users.objects.all().order_by('-username')[:5]
return render_to_response('users/index.html',{'latest_users_list':latest_users_list})


这是template/users下的index.html模板
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>就是这样的</title>
<style type='text/css'>
table{border:1px solid #003366; border-width:1px 0 0 1px; margin:2px 0 2px 0; text-align:center; border-collapse:collapse;}
td,th{border:1px solid #003366; border-width:0 1px 1px 0;margin:2px 0 2px 0;text-align:center;background-color:#FFFFFF;}
th{text-align:center;font-weight:600;font-size:14px;background-color:#003366;color:#FFFFFF}
tr.t1 td {background-color:#fff;} /* 第一行的背景色*/
tr.t2 td {background-color:#eee;}
tr.t3 td {background-color:#ccc;}
</style>
</head>
<body>
<h2>通信录</h2>
<table width='100%' cellpadding='0' cellspacing='0' id='tab'>
<tr>
<th width='17%'>姓名</th>
<th width='17%'>性别</th>
<th width='22%'>年纪</th>
<th width='44%'>地址</th>
</tr>
{% for user in address %}
<tr>
<td>{{ user.name }}</td>
<td>{{ user.sex }}</td>
<td>{{ user.age }}</td>
<td>{{ user.address }}</td>
</tr>
{% endfor %}
</table>
<script type="text/javascript">
<!--
var Ptr=document.getElementById("tab").getElementsByTagName("tr");
function $(){
for(i=1; i<Ptr.length+1; i++){
Ptr[i-1].className = (i%2>0)?"t1":"t2";
}
}
window.onload=$;
for (Var i=0; i<Ptr.length; i++){
Ptr[i].onmouseover=function(){
this.tmpClass = this.className;
this.className = "t3";
};
Ptr[i].onmouseout=function(){
this.className=this.tmpClass;
};
}
//-->
</script>
</body>
</html>



请问这是哪里的错误。找了半天也没有发现问题。有朋友说是模板不存在。。路径映射有问题。也没看出哪里不对来?
...全文
1340 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zheng_j_c 2012-03-23
  • 打赏
  • 举报
回复
setting里面模型没有导入
georgema 2012-03-23
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 cndeer 的回复:]

template 就放在项目文件:Django_Pro的根目录里啊
[/Quote]
那你有没有把Django_Pro的根目录添加到settings.py的TEMPLATE_DIRS里?
tottyandbaty 2012-03-16
  • 打赏
  • 举报
回复
初步判断是,是模版路径错误
这个是我的设置



TEMPLATE_DIRS = (

os.path.join(os.path.dirname(__file__), 'blogapp/tpl').replace('\\','/'),
)


我的app叫做blogapp,然后模板放在blogapp/tpl下。。。另外这个需要import os
cndeer 2012-03-16
  • 打赏
  • 举报
回复
template 就放在项目文件:Django_Pro的根目录里啊
georgema 2012-03-15
  • 打赏
  • 举报
回复
首先你的template放在哪里?是在一个project共享的目录里还是某个app的templates目录下?
cndeer 2012-03-15
  • 打赏
  • 举报
回复
奇了怪了。不管怎么改。都是提示找不到模板
那模板放在好几个地方都有了

TemplateDoesNotExist at /
/users/index.htmRequest Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.3.1
Exception Type: TemplateDoesNotExist
Exception Value: /users/index.htm
Exception Location: F:\Python27\lib\site-packages\django\template\loader.py in find_template, line 138
Python Executable: F:\Python27\python.exe
Python Version: 2.7.2
mobuchuan 2012-03-15
  • 打赏
  • 举报
回复
import os
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django /templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(PROJECT_PATH, "templates")
)
这样试一试。不大清楚你的路径写法是否正确。。
cndeer 2012-03-15
  • 打赏
  • 举报
回复
设置了啊。
是这样吧?
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'./templates',
mobuchuan 2012-03-15
  • 打赏
  • 举报
回复
话说又在settings里面设置templates的路径没有

37,741

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧