1. paster create --template=pylons minispider
2. MySQL,建立数据库minispider
CREATE
TABLE
minispider.titleinfo
( id
INTEGER
UNSIGNED
NOT
NULL
AUTO_INCREMENT,
link
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
,
description
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
,
sitename
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
,
updatetime
TIMESTAMP
NOT
NULL
DEFAULT
0
,
PRIMARY
KEY
(id)
)
3. The Model
1) 修改development.ini,代码如下:
1
#
2
#
minispider - Pylons development environment configuration
3
#
4
#
The %(here)s variable will be replaced with the parent directory of this file
5
#
6
[DEFAULT]
7
debug
=
true
8
email_to
=
you@yourdomain.com
9
smtp_server
=
localhost
10
error_email_from
=
paste@localhost
11
12
[server:main]
13
use
=
egg:Paste
#
http
14
host
=
0.0
.
0.0
15
port
=
5000
16
17
[app:main]
18
use
=
egg:minispider
19
cache_dir
=
%
(here)s
/
data
20
session_key
=
minispider
21
session_secret
=
somesecret
22
23
#
If you'd like to fine-tune the individual locations of the cache data dirs
24
#
for Myghty, the Cache data, or the Session saves, un-comment the desired
25
#
settings here:
26
#
myghty_data_dir = %(here)s/data/templates
27
#
cache_data_dir = %(here)s/data/cache
28
#
session_data_dir = %(here)s/data/sessions
29
30
#
Specify the database for SQLObject to use via pylons.database.PackageHub.
31
#
%(here) may include a ':' character on Windows environments; this can
32
#
invalidate the URI when specifying a SQLite db via path name. Refer to the
33
#
SQLObject documentation for a special syntax to preserve the URI.
34
#
sqlobject.dburi = sqlite:%(here)s/somedb.db
35
sqlobject.dburi
=
mysql:
//
root:
123456
@localhost:
3306
/
minispider
36
37
#
WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
38
#
Debug mode will enable the interactive debugging tool, allowing ANYONE to
39
#
execute malicious code after an exception is raised.
40
#
set debug = false
第35行为添加的部分。
2)在models目录下,建立msmodel.py,代码如下:
from
sqlobject
import
*
from
pylons.database
import
PackageHub
hub
=
PackageHub(
"
minispider
"
)
__connection__
=
hub
class
titleinfo(SQLObject):
link
=
StringCol(length
=
255
)
description
=
StringCol(length
=
255
)
sitename
=
StringCol(length
=
255
)
updatetime
=
DateTimeCol()
修改__init__.py,代码如下:
#
# NOTE
#
# If you plan on using SQLObject, the following should be un-commented and provides
#
# a starting point for setting up your schema
#
from sqlobject import *
#
from pylons.database import PackageHub
#
hub = PackageHub("minispider")
#
__connection__ = hub
#
You should then import your SQLObject classes
#
from myclass import MyDataClass
from
msmodel
import
titleinfo
4.The view
在templates文件夹下建立ms文件夹,在ms文件中建立list.myt,代码如下:
<
html
>
<
head
>
<
title
>
Generated by Mini Spider v0.
1
</
title
>
</
head
>
<
body
>
<
table width
=
"
80%
"
border
=
"
0
"
>
<
tr
>
<
td width
=
"
60%
"
><
strong
>
What
</
strong
></
td
>
<
td width
=
"
20%
"
><
strong
>
Where
</
strong
></
td
>
<
td width
=
"
20%
"
><
strong
>
When
</
strong
></
td
>
</
tr
>
%
for
ti
in
c.titleinfo:
<
tr
>
<
td
><
a href
=
"
<% ti.link %>
"
target
=
"
_blank
"
><%
ti.description
%></
a
></
td
>
<
td
><%
ti.sitename
%></
td
>
<
td
><%
ti.updatetime
%></
td
>
</
tr
>
%
#
endfor
</
table
>
</
body
>
</
html
>
务必注意代码的缩进!浪费了偶半个多小时!
5.The controller
命令行运行:
cd minispider
paster controller ms
将controllers文件夹下ms.py修改,代码如下:
from
minispider.lib.base
import
*
class
MsController(BaseController):
template_prefix
=
'
/ms
'
def
index(self):
redirect_to(action
=
'
list
'
)
def
list(self):
c.titleinfo
=
list(model.titleinfo.select())
return
render_response(self.template_prefix
+
'
/list.myt
'
)
6. run
命令行运行:
paster serve --reload development.ini
ok,访问:http://127.0.0.1:5000/ms
结果类似:
What
|
Where
|
When
|
Baidu
|
Baidu |
2006-12-05 22:18:12 |
Google
|
Google |
2006-12-05 22:18:42 |
初试,功能之强大,操作之简便,初见端倪。
分享到:
相关推荐
The Definitive Guide to Pylons.pdf
In this book, cofounder and lead developer James Gardner brings you a comprehensive introduction to Pylons, the web framework that uses the best of Ruby, Python, and Perl and the emerging WSGI ...
主要介绍了Python Web框架Pylons中使用MongoDB 的例子,大家参考使用
python库,解压后可用。 资源全名:Pylons-0.8.2-py2.3.egg
资源来自pypi官网。 资源全名:Pylons-0.8.2-py2.3.egg
Apress.the.Definitive.Guide.to.Pylons.Dec.2008
pyramid是最新python web开发框架,pylons升级版。
塔架 Pylons是一个快速的Web应用程序开发框架。 笔记定向塔已与repoze.bfg合并,并且现在处于仅维护模式。 强烈建议新项目从新的合并的Web框架。安装。 如果要从源代码安装,可以运行以下命令: $ python setup.py ...
博文链接:https://zsp.iteye.com/blog/178446
可用于UnityVR开发,3D游戏开发,高清天空盒子Skybox素材,游戏环境背景素材,无水印。 让你身临其境的天空盒子,各类题材丰富,都是辛苦搜罗所得的高清exr格式,可以直接用于Unity开发,特别是VR游戏的开发。...
pyramid1.2源码安装包。pyramid是最新python web 开发框架。是pylons的升级版。
zope, pyramid, pylons框架常用模版系统 chameleon zpt的程序员指南
(3)the pylons (or towers) supporting the cable system; (4)the anchor blocks (or anchor piers) supporting the cable system vertically and horizontally, or only vertically, at the extreme ends.
pylons默认的模板就是用的它;相比而言,Django 内建的模板引擎,为了维持所谓模板语法的纯粹性和简单性,更纯粹的满足 MVC 模式的规定,牺牲了很多灵活性,一些高级的功能不得不利用 tag 和 filter 来实现,其写法...
博主介绍说:“日志是一个应用程序的重要组成部分,今天在看pylons对日志的处理时,受到启发,于是plog就诞生了。很多php框架都忽略了日志的重要性(如kohana),往往只是能用,自定义和可扩展性不够,等到程序出了...
从 GitHub 中检出这个包(必须是 Substance D 团队 Pylons 组织的成员): $ git clone git@github.com:Pylons/sdidev.git cd 进入sdidev目录。 从下载 virtualenv 并将其安装到您的系统 Python (2.7+) 中。 安装...
Django,Pylons等几个方面,最后一章也就是第九章,介绍了一些具体例子,也需要 数据库、网页等方面配合。都是俺暂时用不到的。 前几个章节适合大多数Python Coder使用俺就不剧透了。 此书具有Packt 出版书的一般...