代码拉取完成,页面将自动刷新
#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,)
>>>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。