"No template named hello"

 
关于webpy的教程中的一个模板问题...
5 名作者发布了 10 个帖子
 
 
frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" tabindex="0" vspace="0" width="100%" id="I0_1477731757699" name="I0_1477731757699" src="https://apis.google.com/u/0/_/+1/fastbutton?usegapi=1&count=false&size=small&source=google%3Agdf&hl=zh-CN&origin=https%3A%2F%2Fgroups.google.com&url=https%3A%2F%2Fgroups.google.com%2Fd%2Ftopic%2Fpython-cn%2FgCKlyoNB8xo%3Ffromplusone%3D1&gsrc=1p&jsh=m%3B%2F_%2Fscs%2Fabc-static%2F_%2Fjs%2Fk%3Dgapi.gapi.en.8KvJMpFyTwI.O%2Fm%3D__features__%2Frt%3Dj%2Fd%3D1%2Frs%3DAHpOoo97bqw3j5jg4TkTecEOgY44B9P0Vg#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh&id=I0_1477731757699&parent=https%3A%2F%2Fgroups.google.com&pfname=&rpctoken=64192486" data-gapiattached="true" title="+1" style="margin: 0px; padding: 0px; border-width: 0px; border-style: none; position: static; top: 0px; width: 24px; left: 0px; visibility: visible; height: 15px;">
初恋_ 
11/12/12
最近在看web.py的教程,网上中文翻译的太少了,就一点点挖   http://webpy.org/tutorial3
的英文教程看,今天出现了一个问题, 就是在输出html模板的时候报错,贴下教程上的代码
hello.py的是 :
import web
urls = (
'/','hello'
'/bye/','bye')

app=web.application(urls,globals(),True)
render=web.template.render('templates/')

class hello:
    def GET(self):
        return render.hello("Templates demo","Hello","A long time ago....")

class bye:
    def GET(self):
        return render.bye("Templates demo","Bye","14","8","25","42")

if __name__ == "__main__" :
    app.run()

然后模板是建立了templates的文件夹,和hello.py是在同一目录下,里面有templates/hello.html,
templates/bye.html,代码是照抄教程上的,终端运行 python hello.py ,浏览器中报错
<type 'exceptions.AttributeError'>at /
no template named hello...

为什么说模板名称没有hello的命名呢.. 是不是路径不对,我把hello.html和bye.html copy出来也还是不行..

新手上路,没有搜寻到答案,望各位大婶帮帮忙,打扰了.. : (

noah_zxc 
11/12/12

render=web.template.render(' templates/') 变成
render=web.template.render(' templates')就ok了。
- 显示引用文字 -
Hyvi 
11/12/12
可以考虑写成这样 : 我理解下面这种方式是绝对路径。
import os 
os.path.join(os.path.dirname(_ _file__),"tempates/") 
Li Haifeng 
11/12/12
Re: [CPyUG] Re: 关于webpy的教程中的一个模板问题...
2011/12/12 Hyvi  <tanhai...@gmail.com>
可以考虑写成这样 : 我理解下面这种方式是绝对路径。
import os 
os.path.join(os.path.dirname(_ _file__),"tempates/") 

-- 

1.默认是在根目录下/,你可以放在/目录下试试情况。

2.这种方法是可以的。
os.path.join(os.path.dirname(_ _file__),"tempates/") 
 
来自: python-cn`CPyUG`华蟒用户组( 中文Python技术邮件列表)
规则:  http://code.google.com/p/cpyug/wiki/PythonCn
发言:  pyth...@googlegroups.com
退订:  python-cn+...@googlegroups.com (向此发空信即退!)
详情:  http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问!  http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug  http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html



-- 
Li Haifeng
Laboratory of Service Computing Technology and System
Home page: http://tek-life.org

初恋_ 
11/12/12
Re: [CPyUG] Re: 关于webpy的教程中的一个模板问题...
感谢各位大神~解决了 : )

- 显示引用文字 -
> --

> 来自: python-cn`CPyUG`华蟒用户组( 中文Python技术邮件列表)
> 规则:  http://code.google.com/p/cpyug/wiki/PythonCn
> 发言:  pyth...@googlegroups.com
> 退订:  python-cn+...@googlegroups.com (向此发空信即退!)
> 详情:  http://code.google.com/p/cpyug/wiki/PythonCn
> 严正: 理解列表! 智慧提问!  http://wiki.woodpecker.org.cn/moin/AskForHelp
> 强烈: 建议使用技巧: 如何有效地报告Bug
http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html

初恋_ 
11/12/12
Re: [CPyUG] Re: 关于webpy的教程中的一个模板问题...
追问大神,templates下的hello. html和bye.html还是不能访问.. 放在根目录下也不行,只能访问首页...

- 显示引用文字 -
> --
> 来自: python-cn`CPyUG`华蟒用户组( 中文Python技术邮件列表)
> 规则:  http://code.google.com/p/cpyug/wiki/PythonCn
> 发言:  pyth...@googlegroups.com
> 退订:  python-cn+...@googlegroups.com (向此发空信即退!)
> 详情:  http://code.google.com/p/cpyug/wiki/PythonCn
> 严正: 理解列表! 智慧提问!  http://wiki.woodpecker.org.cn/moin/AskForHelp
> 强烈: 建议使用技巧: 如何有效地报告Bug  http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html

DamonChen 
11/12/12
Re: [CPyUG] Re: 关于webpy的教程中的一个模板问题...
bye.html 是不是拼写错误?

templates 目录,放在/目录下,有读写到的权限么?

严格一些是:
os.path.join(os.path.dirname( os.path.abspath(__file__))," tempates") 
- 显示引用文字 -
-- 
To be pythoner
My blog:  http://www.cnblogs.com/ubunoon/
珍珠饰品: http://zjyuezz.cn.alibaba.com/
English blog: http://qtrstudio.com/blog


初恋_ 
11/12/12
Re: [CPyUG] Re: 关于webpy的教程中的一个模板问题...
我说错了 是放在~目录下,不是根目录 templates下的两个html都不能访问, 拼写我检查过了,还是路径的问题吧...
- 显示引用文字 -
DamonChen 
11/12/12
Re: [CPyUG] Re: 关于webpy的教程中的一个模板问题...
路径里面没有中文名吧?最好把你到路径和你写到web. py代码贴详细些,还有你的后台出错信息呢?
- 显示引用文字 -
初恋_ 
11/12/12
Re: [CPyUG] Re: 关于webpy的教程中的一个模板问题...
import web

urls=(
'/','hello',
'/bye/','bye'
)

app = web.application(urls,globals(),True)

render = web.template.render('templates')

class hello:
  def GET(self):
    return render.hello("Templates demo","Hello","A long time ago...")

class bye:
  def GET(self):
    return render.bye("Templates demo","Bye","14","8","25","42","19")

if __name__ =="__main__":
  app.run()

没有中文,访问templates/hello.html是404页面(hello.html是有内容的)
hello.py是在~/目录下,hello.html和bye.html是在~/templates目录下

- 显示引用文字 -


原文地址:https://groups.google.com/forum/#!topic/python-cn/gCKlyoNB8xo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值