关于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;">
|
|
|
|
的英文教程看,今天出现了一个问题,
hello.py的是 :
import web
urls = (
'/','hello'
'/bye/','bye')
app=web.application(urls,
render=web.template.render('
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.
templates/bye.html,代码是照抄教程上的,
<type 'exceptions.AttributeError'>at /
no template named hello...
为什么说模板名称没有hello的命名呢.. 是不是路径不对,我把hello.html和bye.html copy出来也还是不行..
新手上路,没有搜寻到答案,望各位大婶帮帮忙,打扰了.. : (
|
|
render=web.template.render('
render=web.template.render('
|
|
|
|
可以考虑写成这样 : 我理解下面这种方式是绝对路径。import os
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
|
|
> 来自: python-cn`CPyUG`华蟒用户组(
> 规则: http://code.google.com/p/
> 发言: pyth...@googlegroups.com
> 退订: python-cn+...@
> 详情: http://code.google.com/p/
> 严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/
> 强烈: 建议使用技巧: 如何有效地报告Bug
> http://www.chiark.greenend.
|
|
> 来自: python-cn`CPyUG`华蟒用户组(
> 规则: http://code.google.com/p/
> 发言: pyth...@googlegroups.com
> 退订: python-cn+...@
> 详情: http://code.google.com/p/
> 严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/
> 强烈: 建议使用技巧: 如何有效地报告Bug http://www.chiark.greenend.
|
|
templates 目录,放在/目录下,有读写到的权限么?
严格一些是:
os.path.join(os.path.dirname(
To be pythoner
My blog: http://www.cnblogs.com/
珍珠饰品: http://zjyuezz.cn.
|
|
|
|
|
|
urls=(
'/','hello',
'/bye/','bye'
)
app = web.application(urls,globals()
render = web.template.render('
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"
app.run()
没有中文,访问templates/hello.
hello.py是在~/目录下,hello.
- 显示引用文字 -
原文地址:https://groups.google.com/forum/#!topic/python-cn/gCKlyoNB8xo