1 Star 0 Fork 0

yifanes / blog

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

#blog

补充几个坑:

1.通常通过assign分配过去数据的方式有:字符串或者字典

但是这个坑在于传递过去了一个字典后,如果在模板中没有如下一段就报错,而且报错信息和原因牛头不对马嘴

下面看注册字典到模板,模板定义以及报错3段代码:

#tplData 就是预注入的字典数据
return getattr(render, 'error')(self.tplData)

#模板文件
#特别强调,没有一行代码,将会无厘头的一个错
$def with (tplData)

#错误
    <type 'exceptions.TypeError'> at /
__template__() takes no arguments (1 given)

仔细琢磨了下,他报错的意思是说,如果你没有定义变量在模板中,那么你就不要传递参数!

2.在开发环境下,千万不要想当然的抛你自己的异常,下面是挖坑的代码

try:
    moduleList = __import__('action.' + modelName, {}, {}, [modelName])
except Exception ,e:
    #return 'no such model:'+ modelName
    e.message

其实上面__import__ 导包过程不单纯可能是找不到文件,也有可能是找到文件了,结果文件语法有错误

那么,你正好踩到这个雷,写错一个语法,就此悲剧~~~

所以总结了一点,在开发环境建议 return e.message 在生产环境中按照需要给予

3.db在shell中的学习

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import sqlite3 as db
>>> conn = db.connect("D:\\other\\python\\blog\\data\\.cms.db")
>>> cursor = conn.cursor()
>>> cursor.execute("select count(*) from cms")

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    cursor.execute("select count(*) from cms")
OperationalError: no such table: cms
>>> exe = cursor.execute("select count(1) from cms")

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    exe = cursor.execute("select count(1) from cms")
OperationalError: no such table: cms
>>> conn = db.connect("D:/other/python/blog/data/cms.db")
>>> cursor = conn.cursor()
>>> cursor.execute("select count(*) from cms")
<sqlite3.Cursor object at 0x01319F20>
>>> result = cursor.fetchone()
>>> result
(3,)
>>> cursor.description
(('count(*)', None, None, None, None, None, None),)
>>> zip(j[0] for j in cursor.description, result)
SyntaxError: Generator expression must be parenthesized if not sole argument
>>> zip([j[0] for j in cursor.description], result)
[('count(*)', 3)]
>>> j[0] for j in cursor.description
SyntaxError: invalid syntax
>>> result
(3,)
>>>

空文件

简介

blog based on web.py! 展开 收起
Python
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/yifanes/blog.git
git@gitee.com:yifanes/blog.git
yifanes
blog
blog
master

搜索帮助