今天下载并观看pylons的视频教程
http://media.knowledgetap.com/tesla.flv
然后又去按照<<Making a Pylons Blog >>这个教程敲了一点代码
http://wiki.pylonshq.com/display/pylonscookbook/Making+a+Pylons+Blog
收获如下:
1.
@classmethod
可以定义一个类和实例都可以调用方法,参数是类的类型
2.
from randon import sample
sample(xrange(10000),20)
在指定范围中取样
3.
development.ini
配置如数据库地址等等的常量
项目目录下
config/environment.py
启动时初始化pylons的环境,它会读取development.ini到config变量中
model/__ init __.py
定义数据库的表和ORM
websetup.py
建立数据,表结构等等(用命令paster setup-app development.ini执行)
搞定数据库,接下来可以写模板和controller了,明天继续
#model/__ init __.py
metadata = sa.MetaData()
def Table(name,*args,**keys):
return sa.Table(
name,metadata,
sa.Column("id", types.Integer, primary_key=True,autoincrement=True),
*args,**keys
)
def ForeignKey(tabel,*args,**keys):
tabel_name=tabel.name
return sa.Column(
'%s_id'%tabel_name,
types.Integer,
sa.ForeignKey('%s.id'%tabel_name),
*args,
**keys
)
resource_site_table=Table(
"resource_site",
sa.Column("href", types.String()),
sa.Column("title", types.String(255)),
sa.Column("brief", types.String()),
sa.Column("update_time", types.DateTime()),
)
subject_table=Table(
"subject",
ForeignKey(resource_site_table),
sa.Column("href", types.String()),
sa.Column("title", types.String(255)),
sa.Column("update_time", types.DateTime()),
)
plunder_table =Table(
"plunder",
ForeignKey(subject_table),
sa.Column("href", types.String()),
sa.Column("title", types.String(255)),
sa.Column("brief", types.String()),
sa.Column("update_time", types.DateTime(),default=lambda:datetime.now()),
sa.Column("tag", types.String(255)),
sa.Column("author", types.String(255)),
sa.Column("content", types.String()),
)
class ResourceSite(object):
def __str(self):
return self.title
class Subject(object):
def __str(self):
return self.title
class Plunder(object):
def __str(self):
return self.title